~hkArray() error

~hkArray() error

I have this error in my engine, so, i've done a simple example, and i alsow get it. Example is next:

I have main.cpp with code:

#include "HavokTestFramework.h"

boost::shared_ptr htf;

void main()

{

htf = boost::shared_ptr(new HavokTestFramework());

}

and HavokTestFramework.h:

class HavokTestFramework

{

public:

HavokTestFramework();

~HavokTestFramework();

hkMemory *m_memory_manager;

hkThreadMemory *m_thread_memory;

char *m_stack_buffer;

hkpWorld *m_world;

static void error_report_function(const char* str, void* error_output_object)

{

printf("%s", str);

}

};

and HavokTestFramework.cpp

#include "HavokTestFramework.h"

HavokTestFramework::HavokTestFramework()

{

m_memory_manager = new hkPoolMemory();

m_thread_memory = new hkThreadMemory(m_memory_manager, 16);

hkBaseSystem::init(m_memory_manager, m_thread_memory, error_report_function);

m_memory_manager->removeReference();

int stack_size = 2 * 1024 * 1024;

m_stack_buffer = hkAllocate(stack_size, HK_MEMORY_CLASS_BASE);

m_thread_memory->setStackArea(m_stack_buffer, stack_size);

hkpWorldCinfo info;

info.setBroadPhaseWorldSize( 350.0f );

info.m_gravity.set(0, -9.8f, 0);

info.m_contactPointGeneration = hkpWorldCinfo::CONTACT_POINT_ACCEPT_ALWAYS;

info.m_collisionTolerance = 0.1f; // faster, but better 0.01f for accuracy

m_world = new hkpWorld(info);

}

HavokTestFramework::~HavokTestFramework()

{

m_world->markForWrite();

m_world->removeReference();

m_world = HK_NULL;

hkMemory::getInstance().freeRuntimeBlocks();

m_thread_memory->setStackArea(0, 0);

hkDeallocate(m_stack_buffer);

m_thread_memory->removeReference();

hkBaseSystem::quit();

}

Alsow i've done all #includes of havok 5.5 framework, so i can start it.

But when i start it, i get an unhandled exception on m_world->removeReference();

I don't understand what is the problem.

when i don't use boost::shared_ptr (change code of main.cpp to the):

#include "HavokTestFramework.h"

HavokTestFramework* htf;

void main()

{

htf = new HavokTestFramework();

delete htf;

}

it works fine. Can somebody help me?

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Yuriy,
Can you paste the full callstack from the crash (using the Debug configuration)?

-Chris

Maybe I know what is the problem. I made shared_ptr as a global variable, so in method main() it was not removed. It will be removed later, somewhere... when the program is closing, so i think havok resources will be removed first and then will deleted my shared_ptr on that class. Maybe that is the problem. I shouldn't use shared_ptr here. Callstack is:

havok_test.exe!hkpWorld::~hkpWorld() Line 130 + 0x15 bytes

18a164ec()

Hi Yuriy,

Is that the entire callstack of the crash? It sounds kind of like what you described above. You could try using a global variable, that is not a shared_ptr, and cleaning it up at the end of your main. Let me know if that helps.

Thanks,
Sean

Developer Support Engineer
Havok
www.havok.com

I think Sean is right here. The global shared pointer will call ~hkWorld after main exits. This will end up calling hkMemory::getInstance().deallocate(), at a time when there is no hkMemory object.

Yes, Sean, when I use global simple *ptr it works fine :) using shared_ptr here is my mistake.

Leave a Comment

Please sign in to add a comment. Not a member? Join today