Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(7 edits)

I have a problem when I use worker mode for an object. I can get around 200 of the same models on screen at once without lag but the game crashes after running it for around 5 minutes or so. Seems to be a memory leak? I get this error on the games window. 

SBOX_FATAL_MEMORY_EXCEEDED

Here is a test demo, I only have 16gb ram might take a bit longer for other to get the error.

https://www.mediafire.com/file/ec10qwvs5djld87/crash.c3p/file


EDIT: Lowering animation rate or having the objects offscreen does NOT help at all, still crashes. It only prolongs the amount of time that goes by before it crashes. Also exporting with nwjs, the game window simply closes after a while.

My game has 1 enemy monster so far thats 256 tris and a texture of 128x128. The crash happens with 300 of them even when my fps was at max 144 still with no drops.

EDIT: Reuploaded a better test that's 250 models and 144 fps with worker crash.

Thanks, I’ll take a look next week. Thanks for the example.

cool thanks!

I see the crash. After a little research, it _may_ be a chrome bug that gets fixed in chrome 115 when available. I will keep an eye on this when that version releases.

https://stackoverflow.com/questions/75728569/web-worker-memory-leak-when-using-t...

This also may be another bug/issue with chrome and workers where they don't do reliable GC. In fact, I see that if I do manual forcing of GC through Chrome dev tools, I can stop the crash from happening.

I've seen bug reports on this, but no resolution in chrome yet. I will look at this one possible solution which requires the workers to be terminated and created again. I'm not sure what they will do w/ perf and we'll see if it's actually viable.

(2 edits)

Yep its not fixed even in Chrome Canary which is 117, also tried as far back as Chromium 97 same results. Hope your fix helps!

EDIT: In the test that crashes with 250 objects, I was able to get up to 300 objects at 60fps without crashing if I split it up, 150 workers and 150 nonworkers. So having 2 of the same type of enemies in a Object Bank layer, I can split them up while spawning. Not perfect but works ok for now. Will try to see if prefab instances, destroying 3d objects offscreen and respawning onscreen helps with memory.

(1 edit)

This is definitely an issue with worker GC not triggering when it should and not a direct memory leak.

I looked around for possible fixes and there is a complicated one that at least one developer has done where they terminate the worker after a certain amount of time and start a new one 'fresh'. I am not sure this is a good way to go yet, since they were only using one worker, not hundreds of workers like in this test case.

As you noticed, when there is less load in terms of the number of workers, the worker GC have time to activate and lower the memory requirements. As you note not a desired solution, but hopefully a work around for now. For example if in the test case, I delete 1/2 of the models and watch memory, I can se GC kick in on the workers as memory pressure rises. I do not see the same case with the screen full of models.

As a longer term project I will experiment with whether the tear down and worker creation idea would work (I need to do more like retain some of the state from the worker, so animations don't get messed up, so a few logistics to work out before I can start testing.)

Ye, that sounds complicated to fix. For now, splitting objects into 2 with around 35% worker and 65% nonworker is working pretty good. Can definitely see the memory clean itself up after a while if workers not pushed all the way to the limit. Also feels better using only half the memory.

Deleted 160 days ago

Your right, setting rate to anything under 5 helps a bit, but anything under 10 or even 15 looks bad even from far away lol. With rate at 5, I crash at 350 instead of at 300 enemies.

I was making a platformer similar to the game Toree, but as I was adding more and more stuff to the game it then changed to an action game lol.