Not Enough Memory

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
DaggorathMaster
Posts: 37
Joined: Thu Sep 08, 2022 7:29 pm

Not Enough Memory

Post by DaggorathMaster »

I keep getting a crash with the message "not enough memory" in my mod. Just often enough to be annoying, and not consistent enough to track down a cause.
Are there particular things that set that off, and ways to work around it?

I can get the 4GB patch, but really that ignores the core problem - I do not have gigabytes worth of assets or data. This mod isn't half done, so I could see it burning through 4GB soon enough.

I did a LoG1 dungeon with more stuff than this, and no issues with memory. So it's not just drop-dead-awful coding or resource management on my part.

I do have large-ish script data like drop tables, but those shouldn't be anywhere near gigabytes, and don't change much.
I have GUI updates which are called every frame and create small tables, so I suppose the garbage collector could fall behind.
I have added no models or textures yet, which I would think are what would use the most memory.
I did increase particle count on some things.

Are any of those raising red tapestries (flags)?
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Not Enough Memory

Post by minmay »

The thing that usually "sets off" out of memory errors is saving the game, because it creates a big chunk of data and makes a compressed copy of that big chunk of data, using an even bigger amount of memory.
The standard assets, despite being "only" about 1GB, already push you fairly close to the limits due to DirectX claiming a bunch of the 2GB address space for itself; there are a couple custom dungeons out that, like yours, have no custom assets but still often run out of memory because they have lots of objects and import all the standard assets.

The most practical solution is to get rid of any material and sound definitions that you aren't actually using. defineMaterial() loads all the textures you give it, immediately, and keeps them in memory until the dungeon is closed. Same for defineSound().
So for a start, instead of importing standard_assets.lua, copy and paste the contents of standard_assets.lua then delete the lines you don't need. If there's a monster you aren't using in your dungeon (you probably aren't using the lindworm for example), don't import its file and now you've freed up space for a lot more objects.
If you need even more space, start getting rid of individual environment/item materials/sounds you don't want to use. Yes, this is where it starts to get annoying.

If you made a Lua script that uses a ton of memory you'd almost certainly already know it. Like you theorized, Lua scripts that rapidly generate garbage are easy to make by accident, but this is unlikely to be the cause of an out of memory error; garbage collection is pretty aggressive when it needs to be, and saving the game always collects all garbage first.
Particle count doesn't significantly affect memory usage.

I can't tell from your post whether this part is needed, so just in case: memory usage in the editor isn't a super reliable indicator of memory usage in the game. Memory used by sounds and textures should be the same, but objects in the dungeon all get duplicated for the editor preview, the render resolution is changing a lot more often than it does when people play the game, etc.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
DaggorathMaster
Posts: 37
Joined: Thu Sep 08, 2022 7:29 pm

Re: Not Enough Memory

Post by DaggorathMaster »

OK great. I can ditch some assetss, though probably not Lindworm, as the bad guys are a bunch of wizards - might as well have one on a dragon, unless he's a huge RAM hit.

So far this is all in the editor, so saving isn't the issue, but everything being duplicated probably is, and I guess there's no fix.

And yes I know it's annoying and tedious sometimes - welcome to life! But tracking down an inconsistent crash with no trace is more so!
User avatar
DaggorathMaster
Posts: 37
Joined: Thu Sep 08, 2022 7:29 pm

Re: Not Enough Memory

Post by DaggorathMaster »

And also if DX is using so much, the 4GB patch should way more than double what I can add.
mfrost7
Posts: 11
Joined: Mon Aug 15, 2022 10:05 am

Re: Not Enough Memory

Post by mfrost7 »

I have the same Xubuntu 22,04 LTS (wine staging 4.17)
Please help
Post Reply