crash at stepDeltaTime

crash at stepDeltaTime

a24710's picture

Hi

im running vista 64 with visual studio 2008 and have linked the following libs from the debug_multithreaded folder in debug mode and release_multithreaded folder in release mode

hkBase.lib, hkpDynamics.lib, hkpCollide.lib, hkpConstraintSolver.lib, hkpInternal.lib, hkpUtilities.lib

first of all, sorry cause its going to be a long post, i dont like to make long posts full of code, but im totally stuck and have really no idea why the setpDeltaTime is crashing.

ill explain what ive done so maybe you can see the errors

first - initializing the world


hkMemory *memory_manager = new hkPoolMemory();
hkThreadMemory *thread_memory = new hkThreadMemory(memory_manager, 16);
hkBaseSystem::init( memory_manager, thread_memory, errorReportFunction );

memory_manager->removeReference();

//init the thread stack
int stack_size = 1024 * 1000;
thread_stack = hkAllocate( stack_size, HK_MEMORY_CLASS_BASE);
hkThreadMemory::getInstance().setStackArea( thread_stack, stack_size);

//create the world entity
hkpWorldCinfo world_info;
world_info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_DISCRETE;
world_info.m_gravity.set( 0,-9.8f,0);
world_info.m_collisionTolerance = 0.1f;
world_info.setBroadPhaseWorldSize( 150.0f );
world_info.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM );

hkpWorld *world = new hkpWorld( world_info );

hkpAgentRegisterUtil::registerAllAgents( world->getCollisionDispatcher() );

the world seems to be created ok, i have no null pointers and memory frees ok with some more destructor code

now i want to create a rigid body out of a triangle mesh

first create the shape. (vertex data and triangle index data points to float * and unsigned int * data which is valid cause i use it in more places and its ok)


hkpExtendedMeshShape *mesh_shape = new hkpExtendedMeshShape;
const float *vertex_data;
const void *triangle_index_data;

hkpExtendedMeshShape::TrianglesSubpart triangle_subpart;

//vertex data
triangle_subpart.m_vertexStriding = 3 * sizeof(float); //12
triangle_subpart.m_vertexBase = vertex_data;
triangle_subpart.m_numVertices = vertices.size();

triangle_subpart.m_numTriangleShapes = tindices.size();
triangle_subpart.m_indexStriding = 3 * sizeof(unsigned int); //12
triangle_subpart.m_stridingType = hkpExtendedMeshShape::INDICES_INT32;
triangle_subpart.m_indexBase = triangle_index_data;

//mesh_shape->setRadius( 10.0f );
if (mesh_shape != NULL)
mesh_shape->add
TrianglesSubpart(triangle_subpart);


In release mode i get a crash in mesh_shape->addTrianglesSubpart, in debug its ok any ideas?

now create the rigid body


hkpRigidBodyCinfo info;
info.m_shape = mesh_shape;

info.m_motionType = hkpMotion::MOTION_FIXED;
info.m_qualityType = HK_COLLIDABLE_QUALITY_FIXED;

info.m_position.set(initial_position.GetX(), initial_position.GetY(), initial_position.GetZ());
info.m_mass = 1.0;
info.m_collisionResponse = hkpMaterial::RESPONSE_SIMPLE_CONTACT;

/////////
hkpMassProperties massProperties;

hkpInertiaTensorComputer::computeShapeVolumeMassProperties(mesh_shape, 1.0f, massProperties);
info.m_inertiaTensor = massProperties.m_inertiaTensor;
//////////

hkpRigidBody *rigid_body = new hkpRigidBody(info);

mesh_shape->removeReference();

world->addEntity(rigid_body);

rigid_body->removeReference();

Now everything is supposed to be initialized ok and receive no warnings or errors in the error callback function of the world entity, but the stepdelta function crashes and i dont have a clue of whats happening. Also, a lot of functions dont return any error code, which does not help at all

do you see any errors in the code???
again, sorry for the long post


16 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
a24710's picture

also, the call to stepdeltatime is just one call

i have no code before or after this call. I do it in my main loop

dont know if i have to do anything before this call

havokdaniel's picture

Hiya a24710,

Do you have a callstack from when it crashes?

a24710's picture

yep, here it is. It seems that is the integrate function

pruebadx10d.exe!hkpSimulation::integrate(float physicsDeltaTime=0.10000000) Line 105 + 0x12 bytes C++
pruebadx10d.exe!hkpSimulation::stepDeltaTime(float physicsDeltaTime=0.10000000) Line 344 C++
pruebadx10d.exe!hkpWorld::stepDeltaTime(float physicsDeltaTime=0.10000000) Line 2111 + 0x16 bytes C++

havokchris's picture

Hi,
Sounds like something basic like an uninitialized pointer somewhere (although nothing jumps out at me in the code).

You said that mesh_shape->addTrianglesSubpart crashes in release - what's the callstack then?

Also, you've got a check that mesh_shape != NULL. Maybe it's NULL in one configuration but not the other?

Can you try using hkDebugMemory instead of hkPoolMemory to see if that fires any asserts?

-Chris

a24710's picture

the call stack in the release crash is

pruebadx10.exe!calcAabbExtents(const hkpExtendedMeshShape::TrianglesSubpart & part={...}, hkVector4 & scaling={...}, hkAabb & out={...}) Line 748 C++

pruebadx10.exe!hkpExtendedMeshShape::addTrianglesSubpart(const hkpExtendedMeshShape::TrianglesSubpart & part={...}) Line 877 C++


if i try to use hkDebugMemory instead of the pool memory i receive this message from the compiler

: error C2259: 'hkDebugMemory' : cannot instantiate abstract class

thanks

havokdaniel's picture

Hi a24710,

If you're trying to instantiate hkDebugMemory directly, try doing something like this instead:

hkDebugMemory* debugMem = hkDebugMemory::create();

If you're doing your work from the demo framework you can use debug memory by simply supplying the -d parameter when debugging.



Daniel

havokchris's picture

Hi,

calcAabbExtents is quite simple; it iterates over all the vertices and
updates an aabb (in this case, a temporary one). So I'm pretty sure
that something is wrong with your vertex/index data. Can you post a simple set of vertices and indices that's failing? Preferably something really simple like a cube.

Daniel beat me to the hkDebugMemory answer :)

-Chris

a24710's picture

here is the list of vertices and triangles of a simple cube with 8 vertices and 12 triangles. Is it possible that the fact that im using unsigned int as indices instead of int is causing the problem??? (ill try with normal ints to check it)

vertices
[0] -8.6605654 float
[1] -1.2479202 float //vertex 0
[2] 6.0898504 float

[3] 8.6605654 float
[4] -1.2479202 float //vertex 1
[5] 6.0898504 float

[6] -8.6605654 float
[7] 1.2479202 float //vertex 2
[8] 6.0898504 float

[9] 8.6605654 float
[10] 1.2479202 float //vertex 3
[11] 6.0898504 float

[12] -8.6605654 float
[13] 1.2479202 float //vertex 4
[14] -6.0898504 float

[15] 8.6605654 float
[16] 1.2479202 float //vertex 5
[17] -6.0898504 float

[18] -8.6605654 float
[19] -1.2479202 float //vertex 6
[20] -6.0898504 float

[21] 8.6605654 float
[22] -1.2479202 float //vertex 7
[23] -6.0898504 float

triangles

[0] 0 unsigned int
[1] 1 unsigned int //triangle 0
[2] 3 unsigned int

[3] 3 unsigned int
[4] 2 unsigned int //triangle 1
[5] 0 unsigned int

[6] 2 unsigned int
[7] 3 unsigned int //triangle 2
[8] 5 unsigned int

[9] 5 unsigned int
[10] 4 unsigned int //triangle 3
[11] 2 unsigned int
&
nbsp;
[12] 4 unsigned int
[13] 5 unsigned int //triangle 4
[14] 7 unsigned int

[15] 7 unsigned int
[16] 6 unsigned int //triangle 5
[17] 4 unsigned int

[18] 6 unsigned int
[19] 7 unsigned int //triangle 6
[20] 1 unsigned int

[21] 1 unsigned int
[22] 0 unsigned int //triangle 7
[23] 6 unsigned int

[24] 1 unsigned int
[25] 7 unsigned int //triangle 8
[26] 5 unsigned int

[27] 5 unsigned int
[28] 3 unsigned int //triangle 9
[29] 1 unsigned int

[30] 6 unsigned int
[31] 0 unsigned int //triangle 10
[32] 2 unsigned int

[33] 2 unsigned int
[34] 4 unsigned int //triangle 11
[35] 6 unsigned int

thanks again and sorry for making you read such a bunch of numbers :(

a24710's picture

ill try with box shape and sphere shape also and will comment the results

a24710's picture

if i try the hkDebugMemory *debugMem = hkDebugMemory::create(); thing i get a lot of compiling errors

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::~basic_string,class std::allocator >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in hkBase.lib(hkDebugMemory.obj)
6>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::basic_string,class std::allocator >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in hkBase.lib(hkDebugMemory.obj)
6>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in hkBase.lib(hkDebugMemory.obj)
6>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::basic_string,class std::allocator >(class std::basic_string,class std::allocator > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in hkBase.lib(hkDebugMemory.obj)
6>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string,class std::allocator >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in hkBase.lib(hkDebugMemory.obj)
6>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string,class std::allocator >::size(void)const " (?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in hkBase.lib(hkDebugMemory.obj)
6>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "protected: char * __thiscall std::basic_string,class std::allocator >::_Myptr(void)" (?_Myptr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IAEPADXZ) already defined in hkBase.lib(hkDebugMemory.obj)
6>..inpruebadx10d.exe : fatal error LNK1169: one or more multiply defined symbols found

looks like a conflict between the STL and some classes already defined in the hkbase.lib

any ideas???

sorry for asking so much :(

a24710's picture

with the sphere shape i get the same results

i also tested this code before the first call to stepdeltatime

int test = world->getAllocatedSize();
world->findInitialContactPointsOfAllEntities();

test value is 784 for just one sphere in the world and the findinitialcontactpointsofallentities crashes with this callstack

pruebadx10d.exe!hkpSimulation::collideEntitiesBroadPhaseDiscrete(hkpEntity * * entities=0x00e37214, int numEntities=1, hkpWorld * world=0x00fa1100) Line 400 + 0x8 bytes C++
pruebadx10d.exe!hkpSimulation::collideEntitiesDiscrete(hkpEntity * * entities=0x00e37214, int numEntities=1, hkpWorld * world=0x00fa1100, const hkStepInfo & stepInfo={...}, hkpSimulation::FindContacts findExtraContacts=FIND_CONTACTS_EXTRA) Line 688 C++
pruebadx10d.exe!hkpWorld::findInitialContactPoints(hkpEntity * * entities=0x00e37214, int numEntities=1) Line 3477 C++
pruebadx10d.exe!hkpWorld::findInitialContactPointsOfAllEntities() Line 3484 + 0x76 bytes C++




a24710's picture

ok, ive made some progress

im working on my final university project. Its a highly threaded game engine

im telling you these cause i make all the initializations in the main thread and then i pass the pointers to everything to some engine stages. The physic system goes to the update stage which is running in another thread. So basically i do all the havok initialization in one thread, i pass the pointer to the physics system to the update thread and then the update calls the stepdelta

basically i found that the havok step delta needs to be called from the same thread where havok was initialized

I changed some code just to test what happens if i call the havok step from the same thread where havok was initialized and voil. It works. Well, not perfectly, i still have some errors. Some warnings about the only scene object leaving the broadphase and then it crashes, but hey, its a big advance :). Now i have error messages and the simulations steps forward!!!

tomorrow i will continue my odissey, but i feel im pretty near to get it working

thanks for the help

PS: im afraid that if i continue posting so much im going to get banned from this forum :)






havokchris's picture
a24710: basically i found that the havok step delta needs to be called from the same thread where havok was initialized



Ah ha! I think that's the missing piece. You need to create an instance of hkThreadMemory in each of the worker (non-main) threads, and also call hkBaseSystem::initThread on that threa's hkThreadMemory. E.g.

hkThreadMemory* threadMemory( &hkMemory::getInstance(), 16);
hkBaseSystem::initThread( &threadMemory );

Note that here, threadMemory is on the stack, so don't let it go out of scope until you're all done with the worker thread.
There's an assert in hkThreadMemory::getInstance that's supposed to check whether you've called initThread, but unfortunately it's commented out :(

-Chris
havokdaniel's picture
a24710:
PS: im afraid that if i continue posting so much im going to get banned from this forum :)


Any problems you have are bound to be had by other users so don't be afraid to post like there's no tomorrow ;-)
r4ccoon's picture
Quoting - havokdaniel
a24710:
PS: im afraid that if i continue posting so much im going to get banned from this forum :)

Any problems you have are bound to be had by other users so don't be afraid to post like there's no tomorrow ;-)

how about if i want to use only single thread?
i also have the stepdeltatime crashes.

Login to leave a comment.