Question

Or at least I think the problem involves some kind of memory error. I'm making a program in SFML and I'm currently working on the menus using a GUI class that I made just for SFML. Internally, the GUI class uses std::shared_ptr to manage all of its internal pointers. The program consistently crashes after main() exits and all global destructors have been called, and gdb says a break point was triggered in ntdll!WaitForAlpCompletion, which leads me to believe that the problem is memory corruption. Whenever I remove the GUI instantiation from the menu function, it exits and closes with no errors. This seems to indicate GUI as the cause of the crash, except that sub-menus which create and destroy their own instances of GUI can be called and exited without any crashes or break points.

Some psuedocode:

SubMenu
{
    Create GUI
        Do Menu
    Destroy GUI
}

Menu
{
    Create GUI
        Do Menu?SubMenu
    Destroy GUI
}

main
{
    Init Stuff
    Menu
    UnInit Stuff
    Destroy GUI
    return 0
}

//after return
Global Dtors
Breakpoint triggered???

I'm at a loss as to what this could be. I plan on using some memory debugger like valgrind sometime today, but I was wondering if anyone else had any ideas on what this could be.

Was it helpful?

Solution

A heap corruption can be caused with this code:

int main()
{
    int *A(new(std::nothrow) int(10));
    int *B(A);

    delete B;
    delete A;
}

Does any of your code contain this similar situation?

OTHER TIPS

Finally figured it out!!!!! It turns out that std::map calls the destructors of its objects every time it is re-sized, causing the shared_ptr's within to delete their data several times. A few "quick" design changes and fixed :) Thanks guys!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top