"Pages in use at exit" when closing

Godot Version

4.2.1

Question

Been hunting down this bug nearly forever, and cannot get a resolution for it. When I close my game, it lags. Takes 2-3 seconds to close. This ONLY happens in the build version of my game, and I am only able to test the Windows version so far.

When closing the game ran from the Godot editor, it shuts down nearly immediately, and does not throw any errors to the console.

Adding the console wrapper to my build gives me a little more information:

Does anyone have any idea what these errors are?

My game project is large - it’s a complete game, and this is one of the last hold-out bugs - so I don’t know where to start.

One obvious culprit is that I have a background thread that does some “busy waiting” (with a 100 ms OS timeout), to autosave the game. I am very careful in handing off resources, and duplicating when necessary to facilitate saving, and there’s no cross-thread traffic. Of course, in _exit_tree I have to
set a thread-safe flag to false to kill the busy-waiting-loop and then wait_to_finish() on the thread, before exiting the tree.

When completely elliminating the auto-saving thread from my game, the exact same error happens, so I have ruled that out as a cause.

Any help would be greatly appreciated.

Edit: I doubt OpenGL is the issue (although maybe a separate issue, since the last 3 errors aren’t present)- I made a complete copy of the game, changed the renderer backend to Forward+, and still getting this error when closing:

Still hangs for 2-3 seconds.

It appears this may have been fixed in a newer version of the engine. Looks like I have some converting to do :slight_smile:

Months later, I am back. I was hoping 4.3 would fix my issues with this, but I am still getting the same crashing when trying to close my game.

My solution has been to release in debug mode (which is a horrible bandaid). At least the errors are caught.

Still looking for any insights or updates on how to tackle this. I have tried removing components from my game to isolate the issue, but this is a game nearly a year in development, so there’s a lot of stuff in it. The error messages are just too vague to understand where the problem is:

ERROR: Pages in use exist at exit in PagedAllocator: N20RasterizerSceneGLES323GeometryInstanceSurfaceE
   at: ~PagedAllocator (./core/templates/paged_allocator.h:170)
ERROR: Pages in use exist at exit in PagedAllocator: N20RasterizerSceneGLES321GeometryInstanceGLES3E
   at: ~PagedAllocator (./core/templates/paged_allocator.h:170)
ERROR: 1 RID allocations of type 'N5GLES34MeshE' were leaked at exit.
WARNING: Leaked instance dependency: Bug - did not call instance_notify_deleted when freeing.
     at: ~Dependency (servers/rendering/storage/utilities.cpp:56)
ERROR: Buffer with GL ID of 421: leaked 480 bytes.
   at: ~Utilities (drivers/gles3/storage/utilities.cpp:110)
ERROR: Buffer with GL ID of 422: leaked 192 bytes.
   at: ~Utilities (drivers/gles3/storage/utilities.cpp:110)
ERROR: Buffer with GL ID of 423: leaked 72 bytes.
   at: ~Utilities (drivers/gles3/storage/utilities.cpp:110)
ERROR: 1 RID allocations of type 'N17RendererSceneCull8InstanceE' were leaked at exit.
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: cleanup (core/object/object.cpp:2284)
ERROR: 2 resources still in use at exit (run with --verbose for details).
   at: clear (core/io/resource.cpp:604)

Updating again… in case it helps anyone else.
After creating a branch and nuking the majority of my project, I found I had some BoxMeshes and MeshInstances3Ds that were created, but never added to a scene tree, causing a reason leak.

I discovered this by exporting with Debug on, then running the game from the command line with the --verbose flag. Hopefully this helps others track down the issue, as I know a few have had it.