problem with hkStringMap (but not sure)

problem with hkStringMap (but not sure)

siodmak's picture

Hi


I'm having problems with my code and Visual Studio points t a line where myhkStringMap is declared. The code looks like so:

typedef hkStringMap modelcache_t;//VS points here when it crashes in debug mode:static modelcache_t s_MdlCache;Do I need any special stuff to use the StringMap, like enabling managed space in the engine or something similar?This is my call stack:DX_NGD.exe!hkThreadMemory::allocateChunk(int nbytes=192, HK_MEMORY_CLASS cl=HK_MEMORY_CLASS_ARRAY) Line 243 + 0x7 bytes
DX_NGD.exe!hkCachedHashMap::hkCachedHashMap(hkStringMapOperations ops={...}) Line 38
>DX_NGD.exe!`dynamic initializer for 's_MdlCache''() Line 16 + 0x13 bytes
DX_NGD.exe!_cinit(int initFloatingPrecision=1) Line 293 + 0x19 bytes
DX_NGD.exe!__tmainCRTStartup() Line 301 + 0x6 bytesAll I get is a runtime Access Violation. Is this something with Havok or is it just my fault somewhere?
3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
havokchris's picture

Hi,
It's a little hard to see what's going on because the forum mangled your code, but it looks like s_MdlCache is a file-scoped variable, right?

If that's the case, I think what's happening is that the hkCachedHashMap is created as the program is initializing. hkCachedHashMap's constructor is trying to allocate memory via hkThreadMemory, but you haven't set up your hkThreadMemory or hkMemory yet, so it crashes.

Instead, can you s_MdlCache a pointer, and assign it after you've called hkBaseSystem::init?

-Chris

siodmak's picture

Thanks a lot, moving the first call to it after hkBaseSystem::init() helped.

Login to leave a comment.