Fixing a crash when minimizing a window with custom viewport. (#16704) (#18916)

# Objective

Fix a crash when minimizing a window. (#16704) It happens when the
window contains Camera with a custom Viewport.

## Solution

Remove ExtractedCamera when the corresponding camera in main world has
zero target size. It indicates that the window is minimized.

## Testing

Tested in Windows 11.
Previously the split_screen example crashes when the window is
minimized; and with this change, it would not crash. Other behaviors
remain unchanged.
This commit is contained in:
RuelYasa 2025-07-15 04:11:55 +08:00 committed by GitHub
parent 8777dd4144
commit 9751db4d6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -433,6 +433,17 @@ pub fn extract_cameras(
mapper: Extract<Query<&RenderEntity>>,
) {
let primary_window = primary_window.iter().next();
type ExtractedCameraComponents = (
ExtractedCamera,
ExtractedView,
RenderVisibleEntities,
TemporalJitter,
MipBias,
RenderLayers,
Projection,
NoIndirectDrawing,
ViewUniformOffset,
);
for (
main_entity,
render_entity,
@ -452,17 +463,9 @@ pub fn extract_cameras(
) in query.iter()
{
if !camera.is_active {
commands.entity(render_entity).remove::<(
ExtractedCamera,
ExtractedView,
RenderVisibleEntities,
TemporalJitter,
MipBias,
RenderLayers,
Projection,
NoIndirectDrawing,
ViewUniformOffset,
)>();
commands
.entity(render_entity)
.remove::<ExtractedCameraComponents>();
continue;
}
@ -481,6 +484,9 @@ pub fn extract_cameras(
camera.physical_target_size(),
) {
if target_size.x == 0 || target_size.y == 0 {
commands
.entity(render_entity)
.remove::<ExtractedCameraComponents>();
continue;
}