level_load - HeapAlloc vs VirtualAlloc

Posted By: Ch40zzC0d3r

level_load - HeapAlloc vs VirtualAlloc - 01/31/14 09:39

Hello laugh
If I try to load a big map twice my game crashes with a message:
"Out of memory"
I tried everything with nexus and so on but it wont simply work, so I decided finally to debug my game...
I traced some calls and came to this function:
Code:
10040B90



This function allocates memory for everything in my game (maps, models, strings, vars, and so on...)
It uses another function (the first call) which uses HeapAlloc.
I noticed when Im loading my map twice that this function returns an empty EAX/ESI which is normally the address where the map would be extracted and loaded, so the next JE condition is false and we wont jump past the error message "Out of memory". I forced the jump to jump and tried some different memory addresses for ESI, and yeah it worked. But I cant handle that without a debugger, because my hooks will make everything more unstable as it is now.
So, I read on the internet why the hell HeapAlloc can fail, and people said I should use VirtualAlloc instead of HeapAlloc for bigger files. It would be awesome if you could increase the size of the heap or use VirtualAlloc so I can load some larger maps with alot of models preloaded for my firstperson view. Thanks!
Posted By: oliver2s

Re: level_load - HeapAlloc vs VirtualAlloc - 01/31/14 11:17

Everytime I got the "out of memory" error in the past while level loading my textures where too big. Use LOD textures in near distance and use DDS compression.
Posted By: Ch40zzC0d3r

Re: level_load - HeapAlloc vs VirtualAlloc - 01/31/14 11:26

My weapons textures are DDS, but I cant recompile my level at the moment, also its "just" 180MB which is rather small for a game in this age..
The texture size is original size of CSS (source engine) which is not the newestalso (should be arround 512x512 but tga). I hope I can recompile my map and change textures (cuz importing source bsp maps is rather hard) Id love to see a fix for this thing too laugh
Posted By: jcl

Re: level_load - HeapAlloc vs VirtualAlloc - 01/31/14 14:42

There is no "miracle function" that gets more memory out of your PC.

C/C++ programs use 'new' for implicit and 'malloc' for explicit memory allocation. What they do depends on the implementation, but under Windows both call HeapAlloc. Replacing that with VirtualAlloc would make no sense. You would get even more "Out of memory" messages, due to larger chunks. You normally don't call low level allocation functions anyway - malloc/new are supposed to use the optimal allocation method.

When you still have not enough memory for your game, your customers won't have either - so reducing the textures is indeed the first thing to do. Also replace vertex with bones animation.
Posted By: Ch40zzC0d3r

Re: level_load - HeapAlloc vs VirtualAlloc - 01/31/14 15:13

Well, the map is only 180MB and Ive got 8GB RAM + 12GB virtual RAM.
I dont see a reason why it shouldnt have anough memory frown
Thanks for your awnser anyways laugh
Posted By: jcl

Re: level_load - HeapAlloc vs VirtualAlloc - 01/31/14 15:16

Well, the obvious reason is then using >20 GB for your game plus the other tasks on your PC.
Posted By: Ch40zzC0d3r

Re: level_load - HeapAlloc vs VirtualAlloc - 01/31/14 15:30

However, I saw that my nexus raises to 177915 on a near empty map, is that skill ok?
Im using DDs textures, but my guns need 8 textures and Ive got 30 guns shocked
Posted By: jcl

Re: level_load - HeapAlloc vs VirtualAlloc - 01/31/14 15:49

Depends on what's in your map - 177MB seems not so empty to me. But how the nexus rises is irrelevant here. It's allocated at start, so that memory is already gone. It's the further memory that you allocate during gameplay which can produce the "Out of memory" error.
Posted By: Ch40zzC0d3r

Re: level_load - HeapAlloc vs VirtualAlloc - 01/31/14 16:15

Im preloading evreything thats why my nexus is that hight without a map.
And yeah, the map is converted from CSS its not perfect done, WED was about to crash while compiling tongue
Posted By: Truth

Re: level_load - HeapAlloc vs VirtualAlloc - 02/06/14 16:58

I get the 'out of memory' message too. What I do to get around it is to use 'd3d_texlimit = 256;' which limits all the textures in the game to 256x256 thus using less memory. You can change it as low as 64 if you need
Posted By: oliver2s

Re: level_load - HeapAlloc vs VirtualAlloc - 02/07/14 20:26

Originally Posted By: Truth
I get the 'out of memory' message too. What I do to get around it is to use 'd3d_texlimit = 256;' which limits all the textures in the game to 256x256 thus using less memory. You can change it as low as 64 if you need


That's what I said earlier in this thread. Out of memory is very often caused by too much texture memory.
Posted By: Ch40zzC0d3r

Re: level_load - HeapAlloc vs VirtualAlloc - 02/07/14 22:57

Guys, I fixed it thanks xD
I used this function + converted everything to 512^2 dds, renders like 8 times faster and so on. Thank you guys, you revived my game!
© 2024 lite-C Forums