Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawing anything while Godot is offscreen freezes editor and leaks memory #84212

Closed
djrain opened this issue Oct 30, 2023 · 3 comments
Closed

Comments

@djrain
Copy link

djrain commented Oct 30, 2023

Godot version

reproducible in 4.1.2 stable, 4.2.1 stable, 4.2.2 stable

System information

M1 Mac Mini, macOS Ventura/Sonoma, Forward and Mobile renderer

Issue description

After porting our game from 3.5 to 4.1.2, I noticed the editor hanging for a long time (spinning beach ball on Mac) when switching back to Godot from other apps/desktops, often for so long I just have to force quit Godot. I found that it's triggered by any tool script drawing anything in _draw(), and also by certain built in nodes that draw extra things in the viewport, such as Path2D. The problem scales with both the amount of things drawn as well as the time Godot is offscreen. This also causes Godot to accumulate memory use while offscreen (some of which seems to be reclaimed after the stall finishes).

The problem only occurs while the editor is not visible at all on the desktop, i.e. fully hidden by other windows, minimized, on another desktop, etc. Also it only happens when using queue_redraw() repeatedly, just drawing once doesn't do it. Applies to both Vulkan renderers, compatibility seems okay.

Somewhat similar to #64708 and #82769, but reproduced in 4.2 beta 3, so #83096 did not fix this.

Steps to reproduce

Open (don't run) the MRP scene in editor. Minimize Godot for a minute or two, open Godot, it should be frozen for some time before becoming responsive again.

May only apply on macOS

Minimal reproduction project

QueueRedrawBug.zip

@djrain djrain changed the title Custom drawing in tool script causes editor hang and memory leak Drawing anything while Godot is offscreen freezes editor and leaks memory Jun 26, 2024
@stuartcarnie
Copy link
Contributor

I suspect this is an issue with obtaining the nextDrawable, which will block until the window is no longer occluded, unless the allowsNextDrawableTimeout property is true. Even with a timeout, it will still block for 1 second, which could be a cause the hanging you are talking about.

This would require Godot's render loop skips presentation, if the window is fully occluded. Fortunately, this is also fairly easy to check by querying the window's occlusionState

@stuartcarnie
Copy link
Contributor

CleanShot 2024-06-28 at 06 44 18@2x

Seems to be an issue in cleaning up buffers in MoltenVK. I don't see the same problem in Metal.

It appears there is a lot of churn allocating and destroying buffers when drawing those polygons.

@clayjohn
Copy link
Member

Fixed by #100257

@clayjohn clayjohn added this to the 4.4 milestone Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants