[SOLVED] Corrupted Heap

Hello,

when i was testing panda3d bullet i faced the following issue:
when my test program is closed, visual studio 2008 warns of corrupted heap. i have panda3d built with optimization=1 and bullet is also a debug version. after some testing i found that the following three lines are enough to produce the problem:

//plane
BulletPlaneShape plane_shape(LVector3f(0, 0, 1), 1);
BulletRigidBodyNode plane_node(“plane”);
plane_node.add_shape(&plane_shape);

if the third line is commented, the error doesn’t appear!!

here is the call stack:
//================================================================================

msvcr90d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x0013f88c) Line 2103 C++
msvcr90d.dll!_msize_dbg(void * pUserData=0x0013f88c, int nBlockUse=1) Line 1511 + 0x9 bytes C++
msvcr90d.dll!_msize(void * pUserData=0x0013f88c) Line 1459 + 0xb bytes C++
libpandaexpress_d.dll!MemoryUsage::win32_malloc_hook(int alloc_type=3, void * ptr=0x0013f88c, unsigned int size=0, int block_use=1, long request=0, const unsigned char * filename=0x00000000, int line=0) Line 346 + 0xc bytes C++
msvcr90d.dll!_free_dbg_nolock(void * pUserData=0x0013f88c, int nBlockUse=1) Line 1305 + 0x21 bytes C++
msvcr90d.dll!_free_dbg(void * pUserData=0x0013f88c, int nBlockUse=1) Line 1258 + 0xd bytes C++
msvcr90d.dll!free(void * pUserData=0x0013f88c) Line 49 + 0xb bytes C++
libp3dtool_d.dll!MemoryHook::heap_free_single(void * ptr=0x0013f890) Line 242 + 0xc bytes C++
libpandaexpress_d.dll!MemoryUsage::heap_free_single(void * ptr=0x0013f890) Line 252 + 0xf bytes C++
libp3dtool_d.dll!MemoryBase::operator delete(void * ptr=0x0013f890) Line 73 + 0x1d bytes C++
libpandabullet_d.dll!BulletPlaneShape::vector deleting destructor'() + 0x73 bytes C++ libpandabullet_d.dll!unref_delete<BulletConstraint>(BulletConstraint * ptr=0x0013f890) Line 362 + 0x22 bytes C++ libpandabullet_d.dll!PointerToBase<BulletShape>::reassign(BulletShape * ptr=0x00000000) Line 79 + 0x9 bytes C++ libpandabullet_d.dll!PointerToBase<BulletShape>::~PointerToBase<BulletShape>() Line 47 C++ libpandabullet_d.dll!PointerTo<BulletShape>::~PointerTo<BulletShape>() Line 46 + 0xf bytes C++ libpandabullet_d.dll!PointerTo<BulletShape>::scalar deleting destructor’() + 0x17 bytes C++
libpandabullet_d.dll!std::_Destroy<PointerTo >(PointerTo * _Ptr=0x03e41b00) Line 60 C++
libpandabullet_d.dll!std::allocator<PointerTo >::destroy(PointerTo * _Ptr=0x03e41b00) Line 160 + 0x9 bytes C++
libpandabullet_d.dll!std::_Destroy_range<pallocator_array<PointerTo > >(PointerTo * _First=0x03e41b00, PointerTo * _Last=0x03e41b04, pallocator_array<PointerTo > & _Al={…}, std::_Nonscalar_ptr_iterator_tag __formal={…}) Line 234 + 0xc bytes C++
libpandabullet_d.dll!std::_Destroy_range<pallocator_array<PointerTo > >(PointerTo * _First=0x03e41b00, PointerTo * _Last=0x03e41b04, pallocator_array<PointerTo > & _Al={…}) Line 225 + 0x29 bytes C++
libpandabullet_d.dll!std::vector<PointerTo,pallocator_array<PointerTo > >::_Destroy(PointerTo * _First=0x03e41b00, PointerTo * _Last=0x03e41b04) Line 1119 + 0x14 bytes C++
libpandabullet_d.dll!std::vector<PointerTo,pallocator_array<PointerTo > >::_Tidy() Line 1132 C++
libpandabullet_d.dll!std::vector<PointerTo,pallocator_array<PointerTo > >::~vector<PointerTo,pallocator_array<PointerTo > >() Line 560 C++
libpandabullet_d.dll!pvector<PointerTo >::~pvector<PointerTo >() + 0x43 bytes C++
libpandabullet_d.dll!ReferenceCountedVector<PointerTo >::~ReferenceCountedVector<PointerTo >() Line 59 + 0xf bytes C++
libpandabullet_d.dll!ReferenceCountedVector<PointerTo >::scalar deleting destructor'() + 0x16 bytes C++ libpandabullet_d.dll!unref_delete<ReferenceCountedVector<PointerTo<BulletConstraint> > >(ReferenceCountedVector<PointerTo<BulletConstraint> > * ptr=0x01eb04cc) Line 362 + 0x22 bytes C++ libpandabullet_d.dll!PointerToBase<ReferenceCountedVector<PointerTo<BulletConstraint> > >::reassign(ReferenceCountedVector<PointerTo<BulletConstraint> > * ptr=0x00000000) Line 79 + 0x9 bytes C++ libpandabullet_d.dll!PointerToBase<ReferenceCountedVector<PointerTo<BulletConstraint> > >::~PointerToBase<ReferenceCountedVector<PointerTo<BulletConstraint> > >() Line 47 C++ libpandabullet_d.dll!PointerToArrayBase<PointerTo<BulletConstraint> >::~PointerToArrayBase<PointerTo<BulletConstraint> >() Line 170 + 0xf bytes C++ libpandabullet_d.dll!PointerToArray<PointerTo<BulletConstraint> >::~PointerToArray<PointerTo<BulletConstraint> >() + 0x43 bytes C++ libpandabullet_d.dll!BulletBodyNode::~BulletBodyNode() Line 29 + 0x12 bytes C++ libpandabullet_d.dll!BulletRigidBodyNode::~BulletRigidBodyNode() Line 26 + 0xf bytes C++ libpandabullet_d.dll!BulletRigidBodyNode::vbase destructor’() + 0x17 bytes C++
test_project.exe!main(int argc=1, char * * argv=0x0200a730) Line 689 + 0x1c bytes C++
test_project.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
test_project.exe!mainCRTStartup() Line 403 C
//================================================================================

is anybody else having this issue???

thank you in advance for any help.

Welcome to the forums!

This is because those classes are reference counted and supposed to be allocated on the heap, not on the stack. This would be the correct code:

PT(BulletPlaneShape) plane_shape = new BulletPlaneShape(LVector3f(0, 0, 1), 1);
PT(BulletRigidBodyNode) plane_node = new BulletPlaneShape("plane");
plane_node->add_shape(plane_shape);

PS. I’ve moved your thread to the appropriate forum.

rdb, Thank you very much for your quick response and for transfering the subject to the proper forum. :smiley: