core::string destructor is crashing

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
DanielBocksteger
Developer
Posts: 25
Joined: Tue Jan 21, 2014 9:15 pm
Location: Goch, NRW, Germany
Contact:

core::string destructor is crashing

Post by DanielBocksteger »

Hi there,

we've a class, holding some core::stringw properties. When the system (iOS) calls the destructor, it sometimes crashes because the following code tries to free memory space, that hasn't been allocated yet.

1. Class destructor calls iiString.cpp ~string() destructor

Code: Select all

//! Destructor
~string()
{
    allocator.deallocate(array); // delete [] array;
}
2. ... calls irrAllocator.h deallocate(T * ptr)

Code: Select all

//! Deallocate memory for an array of objects
void deallocate(T* ptr)
{
    internal_delete(ptr);
}
3. ... calls irrAllocator.h internal_delete(void* ptr)

Code: Select all

virtual void internal_delete(void* ptr)
{
    operator delete(ptr); // malloc: *** error for object 0x170817650: pointer being freed was not allocated
}
Can anybody tell me, how to solve this issue?

Regards,
Daniel
Best regards,
Daniel Bocksteger

German iOS Developer born in '95.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: core::string destructor is crashing

Post by CuteAlien »

Chances are pretty high that the problem is in another place. For example the string is in some other class and that other class object is invalid that point. For such bugs you have to reduce the problem until you have only a tiny program left which still contains the bug (divide&conquer!). Then you can post that tiny program (which should still compile, but not contain any line anymore which isn't removable while keeping the bug) so others can look at it. Thought usually you find the problem yourself while reducing code like that :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply