Possible memory leak? Issue with changing scenes

Describe the bug
My game has started to freeze when loading in between scenes. I can load up each scene separately and run them just fine but for some reason they won’t load when I advance from scene to scene while inside the game

Ive been dealing with this issue for months now as my game gets bigger and bigger. The only thing that I can find to make it better is to remove objects from the scene or try to reduce file sizes of any models or textures.

It is a 3d game with many .glb models, but even after I compress the heck out of them and make everything ugly, this freeze will still happen after loading enough scenes back to back.

Info i have gathered from testing

. 1. Disabling all extensions does not fix it.
2. Disabling all events does not fix it.
3. Using events to try to unload assets between scene does not fix it (Delete all objects at end of scene, Unload all audio ,etc)
3. Add a short delay between scene transition does not fix it
4. Debugger gives info about Alloctation errors and GLTF errors loading
5. Only thing that fixes it is removing objects/compressing object file sizes, but I have already compressed my files enough and things are looking bad now. Is this an engine limitation? how can I fix it without destroying my visuals?

if I go
Level 1 → Level 2 → Level 3 (freeze on 3)

If I just go Level 3, it works
Any individual level works.

If I go Level 3->4-5 (Freeze on 5)

And so on.

I have found some relevant info in the console

everytime the freeze happens, it gives errors related to the GLTFloader Couldnt load textureblob file://
&
““Array buffer allocation failed””

All audio stops, and the loading bar stops and I have to force quit the game

I asked ChatGPT

My computer has 32gb of ram and never gets anyhere near that, the game is freezing when it takes up 5gb of ram or so (but I am using the preview so the exported game is likely less , hard to see how much the game portion is using)

Is this something i can fix myself, or is it a more fundamental limit I am hitting with something inside of the way models & resources are loaded?

I’d say this is normal…

bcs various things may happen during scene swap that don’t happens when you start a new scene…so say it is a memory leak…wel it could be. …

but then i read “It is a 3d game with many .glb models, but even after I compress the heck out of them and make everything ugly”,

they may not be the culprit but it is not a good sign imho, are you storing something between scene, i mean are these 3D assets deleted during the swap or they stay loaded between scenes?

have you taken into consideration a sort of system which “delete” unused assets “per scene” in a scene before/after the swap?

Thanks for replying!
Yes as mentioned above, I even tried to put ALL objects in each scene into an Object Group, and before calling the scene swap, going “Delete object → Object group EVERYTHING”
(to manually delete all the objects between loads, to try to free memory)
As well as going “Unload all audio” between scenes.
I tried various ways of changing scene, including Pre-loading, and all possible options.

None of it helps the problem.
It is like the engine does not free any memory between scenes, or even deleting objects, and I am hitting some hard limit where it just freezes on loading new scene if I play too many levels.

My game is actually finished besides this issue, so its super disappointing to complete a full game but then i cannot play the whole thing without it freezing!

imo it could be the 3D…from my point of view deleting and reloading a sprite…isn’t the same as deleting and re-loading a 3d model…
I haven’t dig into 3D side…but i guess “something” should stay in memory for the 3D part bcs as i said restoring a 3d object shouldn’t be like restoring a 2d sprite…

…i mean to have a 3D model ready to be loaded…

anyway …it could be a mem leak…but…better wait for an expert answer

Anyone clue in? My game is finished except for these freezes, I really would like to get it fixed

How are you changing scenes?

If you use task Manager, does the memory used increase with the starting of each new scene?

Ty for replying!

This is typically how I change scene.
You get to the end of the level, and it runs this.
( I even tried pressing Yes on the option to “Pause previous scene” on the change scene command, but it doesnt change anything)

Yes, the Memory in task manager goes up for each scene loaded. By about 500mb each scene (There are 6 scenes)

image

I removed one model that was 5mb, and instead replaced it with a handful of smaller individual parts (that all together added up to about 2mb) and now the freeze happens again if I simply load levels back to back - whereas before with the single model I could atleast load the levels back to back without freeze. (But it would freeze eventually if I kept loading levels by skipping around

Now im suspicious its not necessarily the size of files, but if you load too many individual models

Or I dont even know. Just want to finish my game but I cant release it like this. Very disappointed by this whole ordeal, and the lack of support + no one seems to have any clue why its happening is pretty discouraging too. Feels like I wasted my time. The memory management needs some serious investigation. I would warn anyone against this engine at the moment.

Depending on what the conditions are for these event actions, it could be that you’re queueing up multiple scene changes and they could be causing an issue. All wait does is put the actions following it on hold, but keeps processing the other events of the game. So you could end up with 60 scene changes queued up before the first scene change is actioned.

What happens if you remove the wait action?

Ive tried it with and without the wait action, without the unload audio files thing. That was just a desperate random last attempt to see if anything would change.

If it’s to be investigated, I believe the dev prefer a simple project that has the issue. If you can replicate the issue with a bare bones project and a number of scenes loading a number of models, then it may get traction.

Ok i’ll see if I can get a simple project with the same issue

1 Like

before changing scene, try to Delete all Objects from the scene (if they are global one’s, just to make sure, idk how the ‘unload previous scene’ work exactly lmao), u could also try to unload resources via javaScript since global objects are always loaded, but i do not know if it is safe, also, check your extensions, maybe one of them are kinda “breaking” your game.

when i first tested the physics behaivior after some time loading scenes the game just crash, but is just that game i used to test that crash after those conditions, so probably is because of an extension.

i don’t know which one tho, it could be the physics extension itself, but i really don’t know :frowning:

Yes I have tried Deleting all objects from scene before each load, sadly it does not help. I also tried removing ALL extensions, AND events , it also does not help.

I dont have time lately to put together a simple project which replicates the issue. I suspect if you just have dozens of .glb models on each scene across multiple scenes that it will happen, though. I will try to reproduce it when I get a chance


This is from a discord user.

Doesn’t work unfortunately

1 Like

To recreate the issue, I believe you must create multiple different scenes, each with dozens of their own list of exclusive models and objects. Then, after you loud enough scenes back to back, at some point it will not load any more scenes and just freeze upon loading. When you have hit some kind of memory limit. I believe it does not free memory or assets between scenes, which causes this issue.

I have created a simple project which reproduces the issue!
How can I Share it so everyone can see what I mean?

Here is an example of a simple project file showcasing this memory leak (?) issue.
it has 3 scenes, each with their own pile of exclusive models (really the ‘same’ model, but separate files, just cause I was lazy to get a bunch of unique ones)

press Q to go to main menu and load each individual level back to back.
level 1 will load, level 2 will load, upon level 3 it will fail to load once it has sufficiently loaded enough assets to where it clogs (?) the memory and the engine just dies and freezes.

this is exactly the behavior my full finished game has that I am unable to fix.