Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 18, 2009, 11:14:25 AM (15 years ago)
Author:
rgrieder
Message:

Fixed two bugs:

  • Incomplete exception safety in Core::loadGraphics
  • When shutting down, Game would load the GraphicsManager again (due to the unloadGraphics call). Suppressed this for faster shutdown.

Resolved a little issue:

  • Finally figured out a way to handle exceptions caught with catch (…) generically and implemented this function in Game::getExceptionMessage()
  • Also removes the exception translation in the GUIManager and made Game catch CEGUI::Exception as well.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/core/Core.cc

    r5655 r5658  
    303303    void Core::loadGraphics()
    304304    {
    305         if (bGraphicsLoaded_)
    306             return;
     305        // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
     306        Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
    307307
    308308        // Upgrade OGRE to receive a render window
     
    314314
    315315        // Calls the InputManager which sets up the input devices.
    316         scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));
     316        inputManager_.reset(new InputManager(windowHnd));
    317317
    318318        // load the CEGUI interface
    319319        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow()));
    320320
    321         // Dismiss scoped pointer
    322         inputManager_.swap(inputManager);
     321        unloader.Dismiss();
    323322
    324323        bGraphicsLoaded_ = true;
     
    327326    void Core::unloadGraphics()
    328327    {
    329         if (!bGraphicsLoaded_)
    330             return;
    331 
    332328        this->guiManager_.reset();;
    333329        this->inputManager_.reset();;
     
    637633    }
    638634
    639     bool Core::preUpdate(const Clock& time) throw()
    640     {
    641         std::string exceptionMessage;
    642         try
    643         {
    644             if (this->bGraphicsLoaded_)
    645             {
    646                 // process input events
    647                 this->inputManager_->update(time);
    648                 // process gui events
    649                 this->guiManager_->update(time);
    650             }
    651             // process thread commands
    652             this->tclThreadManager_->update(time);
    653         }
    654         catch (const std::exception& ex)
    655         { exceptionMessage = ex.what(); }
    656         catch (...)
    657         { exceptionMessage = "Unknown exception"; }
    658         if (!exceptionMessage.empty())
    659         {
    660             COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl;
    661             COUT(0) << "This should really never happen! Closing the program." << std::endl;
    662             return false;
    663         }
    664         return true;
    665     }
    666 
    667     bool Core::postUpdate(const Clock& time) throw()
    668     {
    669         std::string exceptionMessage;
    670         try
    671         {
    672             if (this->bGraphicsLoaded_)
    673             {
    674                 // Render (doesn't throw)
    675                 this->graphicsManager_->update(time);
    676             }
    677         }
    678         catch (const std::exception& ex)
    679         { exceptionMessage = ex.what(); }
    680         catch (...)
    681         { exceptionMessage = "Unknown exception"; }
    682         if (!exceptionMessage.empty())
    683         {
    684             COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl;
    685             COUT(0) << "This should really never happen! Closing the program." << std::endl;
    686             return false;
    687         }
    688         return true;
     635    void Core::preUpdate(const Clock& time)
     636    {
     637        if (this->bGraphicsLoaded_)
     638        {
     639            // process input events
     640            this->inputManager_->update(time);
     641            // process gui events
     642            this->guiManager_->update(time);
     643        }
     644        // process thread commands
     645        this->tclThreadManager_->update(time);
     646    }
     647
     648    void Core::postUpdate(const Clock& time)
     649    {
     650        if (this->bGraphicsLoaded_)
     651        {
     652            // Render (doesn't throw)
     653            this->graphicsManager_->update(time);
     654        }
    689655    }
    690656}
Note: See TracChangeset for help on using the changeset viewer.