[SOLVED] Crash on shutdown

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

daves
Home away from home
Home away from home
Posts: 253
Joined: Thu Feb 02, 2006 20:12

[SOLVED] Crash on shutdown

Postby daves » Fri Jun 15, 2007 19:40

I've seen this crash before and have worked around it in the past, (though I never fully understood it). I'm seeing it again, and would like to understand my problem.

I preregister CEGUI subscribers with a ControlPanelManager in the following fashion:


Code: Select all

controlPanelManager.registerCallback("record", new CEGUI::Event::Subscriber(&Recorder::handleRecordMenu, this));

bool ControlPanelManager::registerCallback(std::string funcKey, CEGUI::Event::Subscriber *subscriber)
{
   mControlCallbackMap[funcKey] = subscriber;
   return false;
}



Here you see that my ControlPanelManager class keeps track of a map between a function name and the subscriber.

Code: Select all

   typedef std::map<std::string, CEGUI::Event::Subscriber*> ControlCallbackMap;
   ControlCallbackMap mControlCallbackMap;


I subsequently search through this local subscriber map for the functional name and then subscribe for events within a cegui push button window as follows:

Code: Select all

   ControlCallbackMap::iterator refitr = mControlCallbackMap.find(ctlItr->second.referenceName);
   if(refitr != mControlCallbackMap.end())
   {
      window->subscribeEvent(evtType, *(refitr->second));
      return 0;
   }


The application works fine and does everything I want it to do, except it crashes on shutdown.

On application destruction I get an "unhandled exception" at the following delete deep down in cegui:

Code: Select all

void SubscriberSlot::cleanup()
{
    delete d_functor_impl;
    d_functor_impl = 0;
}


Why is cegui dieing right at this delete? I imagine this has something to do with the fact that I'm trying to keep track of the list of callback functions as a function of "functional name".

Can someone please help me understand this crash?


--------------------------------------------------------------------------


The problem I had was in application shutdown. My application architecture supports plugins that are loaded as dlls'. One of the plugins was installing its self into the menuing system provided by the main application. This menuing system (of course) uses CEGUI at its core. The problem was in the order with which I destroyed application elements on shutdown. Specifically application plugins were uninstalled before the gui system was destroyed. Since one of the plugins had created gui elements and those elements lived in the memory space of the plugin, that memory space was no longer valid subsequent to the unload of the plugin library. Hence when the gui system was eventually destroyed and that plugins gui element was "deleted" the memory was no longer viable.

Simple fix: ensure that gui system is last thing I create, and first thing I destroy!

Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 10 guests