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/Game.cc

    r5651 r5658  
    3737#include <exception>
    3838#include <boost/weak_ptr.hpp>
     39#include <CEGUIExceptions.h>
    3940
    4041#include "util/Debug.h"
     
    197198
    198199            // Core preUpdate (doesn't throw)
    199             if (!this->core_->preUpdate(*this->gameClock_))
    200             {
     200            try
     201                { this->core_->preUpdate(*this->gameClock_); }
     202            catch (...)
     203            {
     204                COUT(0) << "An exception occurred in the Core preUpdate: " << Game::getExceptionMessage() << std::endl;
     205                COUT(0) << "This should really never happen! Closing the program." << std::endl;
    201206                this->stop();
    202207                break;
     
    207212
    208213            // Core postUpdate (doesn't throw)
    209             if (!this->core_->postUpdate(*this->gameClock_))
    210             {
     214            try
     215                { this->core_->postUpdate(*this->gameClock_); }
     216            catch (...)
     217            {
     218            COUT(0) << "An exception occurred in the Core postUpdate: " << Game::getExceptionMessage() << std::endl;
     219            COUT(0) << "This should really never happen! Closing the program." << std::endl;
    211220                this->stop();
    212221                break;
     
    241250                    this->loadState(requestedStateNode->name_);
    242251                }
    243                 catch (const std::exception& ex)
     252                catch (...)
    244253                {
    245                     COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << ex.what() << std::endl;
     254                    COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << Game::getExceptionMessage() << std::endl;
    246255                    // All scheduled operations have now been rendered inert --> flush them and issue a warning
    247256                    if (this->requestedStateNodes_.size() > 1)
    248                         COUT(1) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << std::endl;
     257                        COUT(4) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << std::endl;
    249258                    this->requestedStateNodes_.clear();
    250259                    break;
     
    262271            it != this->loadedStates_.end(); ++it)
    263272        {
    264             std::string exceptionMessage;
    265273            try
    266274            {
     
    273281                    this->subtractTickTime(static_cast<int32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
    274282            }
    275             catch (const std::exception& ex)
    276             { exceptionMessage = ex.what(); }
    277283            catch (...)
    278             { exceptionMessage = "Unknown exception"; }
    279             if (!exceptionMessage.empty())
    280             {
    281                 COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << exceptionMessage << std::endl;
     284            {
     285                COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << Game::getExceptionMessage() << std::endl;
    282286                COUT(1) << "This should really never happen!" << std::endl;
    283287                COUT(1) << "Unloading all GameStates depending on the one that crashed." << std::endl;
     
    585589            state->deactivate();
    586590        }
     591        catch (...)
     592        {
     593            COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << Game::getExceptionMessage() << std::endl;
     594            COUT(2) << "         There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl;
     595        }
     596        // Check if graphics is still required
     597        if (!bAbort_)
     598        {
     599            bool graphicsRequired = false;
     600            for (unsigned i = 0; i < loadedStates_.size(); ++i)
     601                graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
     602            if (!graphicsRequired)
     603                this->unloadGraphics();
     604        }
     605        this->bChangingState_ = false;
     606    }
     607
     608    /*static*/ std::string Game::getExceptionMessage()
     609    {
     610        std::string exceptionMessage;
     611        try
     612        {
     613            // rethrow
     614            throw;
     615        }
    587616        catch (const std::exception& ex)
    588617        {
    589             COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << ex.what() << std::endl;
    590             COUT(2) << "         There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl;
    591         }
    592         // Check if graphics is still required
    593         bool graphicsRequired = false;
    594         for (unsigned i = 0; i < loadedStates_.size(); ++i)
    595             graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
    596         if (!graphicsRequired)
    597             this->unloadGraphics();
    598         this->bChangingState_ = false;
     618            return ex.what();
     619        }
     620        catch (const CEGUI::Exception& ex)
     621        {
     622#if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6
     623            return GeneralException(ex.getMessage().c_str()).getDescription();
     624#else
     625            return GeneralException(ex.getMessage().c_str(), ex.getLine(),
     626                ex.getFileName().c_str(), ex.getName().c_str()).getDescription();
     627#endif
     628        }
     629        catch (...)
     630        {
     631            return "Unknown exception";
     632        }
    599633    }
    600634
Note: See TracChangeset for help on using the changeset viewer.