floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.53k stars 467 forks source link

macOS huge memory usage when window minimized #1067

Closed oviano closed 1 week ago

oviano commented 1 week ago

Greetings!

I just updated to the latest sokol_gfx version, so I worked my way through the various API changes, the replacement of context with environment, the changes to the way swapchain information is provided etc.

All working except now when I minimise my macOS app, it starts gobbling up huge amounts of memory until I unminimize it.

The screenshot of the profiler shows that it seems to be creating some sort of new surfaces every frame when the window is minimised.

I'm not using the sapp/glue code, so I wondered if this was happening to anyone else?

It seems that I can control this if I detect when the window is minimised and restored and then disable calls to render each frame, but I wonder if this is something that needs fixing in sokol. It's certainly new behaviour.

I've checked my code vs sapp for macOS etc and I can't see that sapp is doing anything like this - it seems to always call frame_func() inside drawInMTKView, which I am doing too.

Any thoughts @floooh?

Screenshot 2024-06-20 at 12 02 31
oviano commented 1 week ago

Ah never mind, this turned out to be a quirk of the multithreaded manner in which I am using sokol.

Pre-update, sokol was calling the callback to get the drawable, and thus was in the main render thread.

Post-update, I was populating the swapchain info in my update thread as it is now stored in the sg_pass structure.

I just needed to make sure that it gets populated in the main render thread as before.

Closing this now!