sean.thurston:Hi gonx,
Try moving your unmarkForWrite() method call to after your cloning code. See if that helps.
Thanks,
Sean
Hi sean,
Many thanks for your informative and timely response. It definitely did helped the problem.
![Open-mouthed smiley [:-D]](/isn/Community/en-US/emoticons/emotion-2.gif)
. But now I'm encountering some other stack traces which i am unable to find the cause. The debugger currently breaks at a '}' so i am unable to figure out the exact problem. The stack trace and source code to my initHavok method are included below:
I have some thoughts on this but just want to ask again with the stack trace below so i can identify the source of the error.
1. Does the stack below indicate that I have to again use a markForWrite/unmarkForWrite to some hkpRigidBody that havok can't seem to destroy?
2. Or i forgot to do a <object>->removeReference somewhere?
=========
Stack
=========
> testy.exe!hkMultiThreadCheck::accessCheck(hkMultiThreadCheck::AccessType type=HK_ACCESS_RW) Line 177 + 0x67 bytes C++
testy.exe!hkMultiThreadCheck::accessCheckWithParent(const hkMultiThreadCheck * parentLock=0x03b2bd98, hkMultiThreadCheck::AccessType parentType=HK_ACCESS_IGNORE, const hkMultiThreadCheck & lock={...}, hkMultiThreadCheck::AccessType type=HK_ACCESS_RW) Line 245 + 0xd bytes C++
testy.exe!hkpRigidBody::~hkpRigidBody() Line 309 + 0x24 bytes C++
testy.exe!hkpRigidBody::`scalar deleting destructor'() + 0x8 bytes C++
testy.exe!cleanupLoadedObjecthkpRigidBody(void * p=0x03b55fd0) Line 22 + 0xc bytes C++
testy.exe!hkPackfileData::callDestructors() Line 33 + 0x39 bytes C++
testy.exe!hkPackfileData::~hkPackfileData() Line 44 C++
testy.exe!hkBinaryPackfileReader::BinaryPackfileData::`scalar deleting destructor'() + 0x8 bytes C++
testy.exe!hkBinaryPackfileReader::~hkBinaryPackfileReader() Line 339 C++
testy.exe!HavokPhysics::initHavok(std::vector<hkpRigidBody *,std::allocator<hkpRigidBody *> > * tempbodies=[0x00000002](0x03b2a100,0x03b29f00)) Line 355 + 0xf bytes C++
testy.exe!OgreFrameListener::OgreFrameListener(Ogre::RenderWindow * win=0x0144fcc8, Ogre::Camera * cam=0x014a6140, Ogre::SceneManager * sceneMgr=0x0149c630) Line 26 C++
testy.exe!TutorialApplication::createFrameListener() Line 193 + 0x43 bytes C++
testy.exe!ExampleApplication::setup() Line 140 + 0xf bytes C++
testy.exe!ExampleApplication::go() Line 89 + 0xf bytes C++
testy.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, char * strCmdLine=0x00161f01, HINSTANCE__
* __formal=0x00000000) Line 218 + 0x8 bytes C++
testy.exe!__tmainCRTStartup() Line 574 + 0x35 bytes C
testy.exe!WinMainCRTStartup() Line 399 C
kernel32.dll!7c816ff7()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
testy.exe!hkpLinearParametricCurve::getBinormal(float t=-2.3555805e-038, hkVector4 & up={...}) Line 314 + 0x82 bytes C++
=============
Source
=============
void HavokPhysics::initHavok(std::vector<hkpRigidBody *> *tempbodies) {
// Initialize the base system including our memory system
hkPoolMemory* memoryManager = new hkPoolMemory();
threadMemory = new hkThreadMemory(memoryManager, 16);
hkBaseSystem::init( memoryManager, threadMemory, errorReport );
memoryManager->removeReference();
// We now initialize the stack area to 100k (fast temporary memory to be used by the engine).
//char* stackBuffer;
{
int stackSize = 0x100000;
stackBuffer = hkAllocate<char>( stackSize, HK_MEMORY_CLASS_BASE);
hkThreadMemory::getInstance().setStackArea( stackBuffer, stackSize);
}
{
// Create the physics world
//hkpWorld* physicsWorld;
/*
{
// The world cinfo contains global simulation parameters, including gravity, solver settings etc.
hkpWorldCinfo worldInfo;
// Set the simulation type of the world to multi-threaded.
worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;
physicsWorld = new hkpWorld(worldInfo);
}
*/
// Open the file
hkIstream infile( "test_Default.hkx" );
if(infile.isOk()){
WriteToLog("infile is OK!!
");
}
// Load the file into a binary packfile reader. Use a hkXmlPackfileReader here if your data is XML.
hkBinaryPackfileReader packfileReader;
packfileReader.loadEntireFile( infile.getStreamReader() );
// Version contents
hkVersionUtil::updateToCurrentVersion( packfileReader, hkVersionRegistry::getInstance(
) );
// Get the contents of the binary packfile.
packfileContents = static_cast<hkRootLevelContainer*>(packfileReader.getContents( hkRootLevelContainerClass.getName() ));
// Get the top level object in the file
//hkTypeInfoRegistry reg;
//hkRegisterHavokClasses::registerAll(reg);
//hkpPhysicsData* physicsData = static_cast<hkpPhysicsData*>( packfileReader.getContents( &hkpPhysicsDataClass, ® ) );
// Store a reference to the physics data in the packfile contents container
physicsData = static_cast<hkpPhysicsData*>(packfileContents->findObjectByType( hkpPhysicsDataClass.getName() ));
WriteToLog("[HavokPhysics 1] physicsData done..size(%d)
", physicsData->getPhysicsSystems().getSize());
(*physicsData->getWorldCinfo()).m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;
// Create a world and add the physics systems to it
physicsWorld = new hkpWorld( *physicsData->getWorldCinfo() );
//
// Pre-allocate some larger memory blocks. These are used by the physics system when in multithreaded mode
// The amount and size of these depends on your physics usage. Larger simulation islands will use larger memory blocks.
//
{
hkMemory::getInstance().preAllocateRuntimeBlock(512000, HK_MEMORY_CLASS_BASE);
hkMemory::getInstance().preAllocateRuntimeBlock(256000, HK_MEMORY_CLASS_BASE);
hkMemory::getInstance().preAllocateRuntimeBlock(128000, HK_MEMORY_CLASS_BASE);
hkMemory::getInstance().preAllocateRuntimeBlock(64000, HK_MEMORY_CLASS_BASE);
hkMemory::getInstance().preAllocateRuntimeBlock(32000, HK_MEMORY_CLASS_BASE);
hkMemory::getInstance().preAllocateRuntimeBlock(16000, HK_MEMORY_CLASS_BASE);
hkMemory::getInstance().preAllocateRuntimeBlock(16000, HK_MEMORY_CLASS_BASE);
}
//
// When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
// to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread
// must call markForRead / markFo
rWrite before it modifies the world to enable these checks.
//
physicsWorld->markForWrite();
//
// Register all collision agents, even though only box - box will be used in this particular example.
// It's important to register collision agents before adding any entities to the world.
//
{
hkpAgentRegisterUtil::registerAllAgents( physicsWorld->getCollisionDispatcher() );
}
//
// Create a multi-threading utility. This utility will create a number of threads that will run the
// physics step in parallel. The main thread calls functions in the utility which signal these threads
// to start a new step, or wait for step completion.
//
hkpMultithreadingUtilCinfo info;
// Add all the physics systems to the world
for ( int i = 0; i < physicsData->getPhysicsSystems().getSize(); ++i )
{
physicsWorld->addPhysicsSystem( physicsData->getPhysicsSystems()[i] );
}
info.m_world = physicsWorld;
info.m_numThreads = NUM_THREADS;
// In this example we enable timers. The multi-threading util will allocate a buffer per thread for capturing timer data.
// If you leave this flag to false, no timers will be enabled.
info.m_enableTimers = true;
multithreadingUtil = new hkpMultithreadingUtil(info);
//
// Initialize the visual debugger so we can connect remotely to the simulation
// The context must exist beyond the use of the VDB instance, and you can make
// whatever contexts you like for your own viewer types.
//
context = new hkpPhysicsContext();
hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers
context->addWorld(physicsWorld); // add the physics world so the viewers can see it
hkVisualDebugger* vdb = setupVisualDebugger(context);
context->m_monitorStreamBegins.setSize(NUM_THREADS);
context->m_monitorStreamEnds.setSize(NUM_THREADS);
WriteToLog("[HavokPhysics 2]
physicsData done..size(%d)
", physicsData->getPhysicsSystems().getSize());
for(int i = 0; i < physicsData->getPhysicsSystems().getSize(); i++) {
hkpPhysicsSystem *ps = physicsData->getPhysicsSystems()[i];
for(int j=0; j<ps->getRigidBodies().getSize();j++) {
hkpRigidBody *rb = ps->getRigidBodies()[j] ;
hkpRigidBody *cloney = rb->clone();
rb->removeReference();
WriteToLog("pushing name=%s mass=%f
",cloney->getName(), cloney->getMass());
tempbodies->push_back(cloney);
}
}
physicsWorld->unmarkForWrite();
WriteToLog("Got %d rigid bodies
", tempbodies->size());
}
}
Thanks.