mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Disable camera on window close (#8802)
# Objective - When a window is closed, the associated camera keeps rendering even if the RenderTarget isn't valid anymore. - This is essentially just wasting a lot of performance. ## Solution - Detect the window close event and disable any camera that used the window has a RenderTarget. ## Notes It's possible a similar thing could be done for camera that use an image handle, but I would fix that in a separate PR.
This commit is contained in:
parent
c1fd505f9c
commit
75da2e7adf
1 changed files with 15 additions and 3 deletions
|
@ -31,12 +31,24 @@ impl Node for CameraDriverNode {
|
|||
world: &World,
|
||||
) -> Result<(), NodeRunError> {
|
||||
let sorted_cameras = world.resource::<SortedCameras>();
|
||||
let windows = world.resource::<ExtractedWindows>();
|
||||
let mut camera_windows = HashSet::new();
|
||||
for sorted_camera in &sorted_cameras.0 {
|
||||
if let Ok(camera) = self.cameras.get_manual(world, sorted_camera.entity) {
|
||||
if let Some(NormalizedRenderTarget::Window(window_ref)) = camera.target {
|
||||
camera_windows.insert(window_ref.entity());
|
||||
let Ok(camera) = self.cameras.get_manual(world, sorted_camera.entity) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let mut run_graph = true;
|
||||
if let Some(NormalizedRenderTarget::Window(window_ref)) = camera.target {
|
||||
let window_entity = window_ref.entity();
|
||||
if windows.windows.get(&window_entity).is_some() {
|
||||
camera_windows.insert(window_entity);
|
||||
} else {
|
||||
// The window doesn't exist anymore so we don't need to run the graph
|
||||
run_graph = false;
|
||||
}
|
||||
}
|
||||
if run_graph {
|
||||
graph.run_sub_graph(
|
||||
camera.render_graph.clone(),
|
||||
vec![],
|
||||
|
|
Loading…
Reference in a new issue