Memory leaks and crashing on shutdown

Memory leaks and crashing on shutdown

Hi, I have a bit of a 2 part question. First, the memory leaks. 

Here is an example of the output I get from checking memory:

Memory Leaked (4 times with this stack):

Address=0x110A4010 size=74 flags='Heap' thread=1736 time=0.39
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\base\system\stacktracer\impl\hkstacktracerwin32.cxx(229):'hkStackTracer::getStackTrace'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\base\memory\system\checking\hkcheckingmemorysystem.cpp(678):'hkCheckingMemorySystem::checkedAlloc'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\base\memory\system\checking\hkcheckingmemorysystem.cpp(51):'hkCheckingMemorySystem::AllocatorForwarder::bufAlloc'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\serialize\data\util\hkdataobjecttonative.cpp(161):'hkDataObjectToNative::copyIntoNativeArray'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\serialize\data\util\hkdataobjecttonative.cpp(962):'hkDataObjectToNative::fillNativeMembers'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\serialize\data\util\hkdataobjectutil.cpp(366):'Copier::deepCopyToNative'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\serialize\data\util\hkdataobjectutil.cpp(399):'Copier::toObject'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\serialize\data\util\hkdataobjectutil.cpp(453):'hkDataObjectUtil::toObjectWithRegistry'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\serialize\util\hkserializeutil.cpp(513):'hkSerializeUtil::loadOnHeap'
y:\build\20120405_200003_pcxsperpetualkeycode\source\common\serialize\util\hkserializeutil.cpp(542):'hkSerializeUtil::loadOnHeap'

Below this in the output are parts of my code that lead to the memory leak. I have

hkObjectResource *loadedAnimation = hkSerializeUtil::loadOnHeap( animSkelPath.c_str() );
hkRootLevelContainer *animationContainer = loadedAnimation->stealContents<hkRootLevelContainer>();
delete loadedAnimation;

hkaAnimationContainer *ac =(hkaAnimationContainer*)( animationContainer->findObjectByType(
hkaAnimationContainerClass.getName() ) );

hkaSkeleton *skeleton = NULL;
if( ac->m_skeletons.getSize() != 1 )
{
std::cout << ac->m_skeletons.getSize() << " skeletons found!---------------------" << std::endl;
m_animatedSkeleton = NULL;
}
else
{
skeleton = ac->m_skeletons[0];
m_animatedSkeleton = new hkaAnimatedSkeleton( skeleton );
skeleton->addReference();
}

delete animationContainer;

as the code which is causing the memory leak. I'm not sure what I'm doing wrong, really. When I'm shutting down my application, I am 100 percent sure that m_animatedSkeleton has its reference count reduced to zero. I am leaking memory from all of the places in my code that I load from files, so I assume it must be something wrong with my syntax there. I will put the second question in a comment to make it easier to tell between them.

EDIT: I seem to have found the solution. Removing all references on an animatedSkeleton will not remove references on its related binding. However, removing reference on the binding will remove reference of the animatedSkeleton. I'm not sure how why this is.

2 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

The second problem I am having is with using a custom debug handler for drawing shapes. I have inherited from hkDebugDisplayHandler and everything works great. The code for initializing it (basically straight out of the manual) looks like this:

hkpPhysicsContext::registerAllPhysicsProcesses();
hkpPhysicsContext *context = new hkpPhysicsContext;
context->addWorld( m_world );

hkArray<hkProcessContext*> contexts;
contexts.pushBack( context );

DebugDisplay *displayHandler = new DebugDisplay;

hkArray<const char*> processNames;
processNames.pushBack( hkpShapeDisplayViewer::getName() );
processNames.pushBack( hkpBroadphaseViewer::getName() );
processNames.pushBack( hkpActiveContactPointViewer::getName() );
processNames.pushBack( hkpPhantomDisplayViewer::getName() );
hkArray<hkProcess*> processes;
for( int i = 0; i < processNames.getSize(); ++i )
{
hkProcess *process = hkProcessFactory::getInstance().createProcess( processNames[i],
contexts );
HK_ASSERT2( 0x30675a6b, process, "Failed to create - did you register all the "
"process for the product(s) you are using?" );
process->m_inStream = HK_NULL;
process->m_outStream = HK_NULL;
process->m_processHandler = HK_NULL;
process->m_displayHandler = displayHandler;
process->init();
processes.pushBack( process );

However, when I include this code in my application, I crash after the following lines

m_world->removeReference();

hkBaseSystem::quit();
hkMemoryInitUtil::quit();

It doesn't seem to matter whether or not I have deleted the memory in the processes or contexts, although I'm not sure how to delete my special debug display correctly. I'm not really sure why it is making  the application crash.

This is where the crash leads me in the havok code: (hkMemoryRouter.h)

/// Allocation which is likely to persist. Not thread local.
inline Allocator& heap() { return *m_heap; }

Help?

EDIT: Now I feel silly for posting both of these. I found the answer to my problem here: http://software.intel.com/en-us/forums/topic/285318

not sure why every time I finally decide to post an issue to the forums I seem to figure it out before I get an answer...

Connectez-vous pour laisser un commentaire.