summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-08-13 23:09:30 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-08-13 23:09:30 +0200
commit5b45911856442ee7cbd451125c47fd13f21db58e (patch)
treed843bc18e4b777628faec617510d663e5cfaa01a /src/app
parenta2dd39960b5851f8e62adf59b11b36ba14626468 (diff)
downloadcolobot-5b45911856442ee7cbd451125c47fd13f21db58e.tar.gz
colobot-5b45911856442ee7cbd451125c47fd13f21db58e.tar.bz2
colobot-5b45911856442ee7cbd451125c47fd13f21db58e.zip
Improved error messages
Added some logging and improved error messages displayed to user
Diffstat (limited to 'src/app')
-rw-r--r--src/app/app.cpp64
-rw-r--r--src/app/app.h6
-rw-r--r--src/app/main.cpp6
3 files changed, 49 insertions, 27 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index a0518db..182e0fd 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -149,6 +149,8 @@ bool CApplication::ParseArguments(int argc, char *argv[])
bool CApplication::Create()
{
+ GetLogger()->Info("Creating CApplication\n");
+
// TODO: verify that data directory exists
// Temporarily -- only in windowed mode
@@ -161,6 +163,9 @@ bool CApplication::Create()
m_robotMain = new CRobotMain(m_iMan); */
+ std::string standardInfoMessage =
+ "\nPlease see the console output or log file\n"
+ "to get more information on the source of error";
/* SDL initialization sequence */
@@ -169,18 +174,18 @@ bool CApplication::Create()
if (SDL_Init(initFlags) < 0)
{
- SystemDialog( SDT_ERROR, "COLOBOT - Fatal Error",
- "SDL initialization error:\n" +
- std::string(SDL_GetError()) );
+ m_errorMessage = std::string("SDL initialization error:\n") +
+ std::string(SDL_GetError());
+ GetLogger()->Error(m_errorMessage.c_str());
m_exitCode = 2;
return false;
}
if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0)
{
- SystemDialog( SDT_ERROR, "COLOBOT - Fatal Error",
- std::string("SDL_Image initialization error:\n") +
- std::string(IMG_GetError()) );
+ m_errorMessage = std::string("SDL_Image initialization error:\n") +
+ std::string(IMG_GetError());
+ GetLogger()->Error(m_errorMessage.c_str());
m_exitCode = 3;
return false;
}
@@ -190,10 +195,10 @@ bool CApplication::Create()
if (m_private->surface == NULL)
{
- SystemDialog( SDT_ERROR, "COLOBT - Fatal Error",
- std::string("SDL error while setting video mode:\n") +
- std::string(SDL_GetError()) );
- m_exitCode = 2;
+ m_errorMessage = std::string("SDL error while setting video mode:\n") +
+ std::string(SDL_GetError());
+ GetLogger()->Error(m_errorMessage.c_str());
+ m_exitCode = 4;
return false;
}
@@ -214,9 +219,8 @@ bool CApplication::Create()
m_device = new Gfx::CGLDevice(m_deviceConfig);
if (! m_device->Create() )
{
- SystemDialog( SDT_ERROR, "COLOBT - Fatal Error",
- std::string("Error in CDevice::Create()") );
- m_exitCode = 1;
+ m_errorMessage = std::string("Error in CDevice::Create()\n") + standardInfoMessage;
+ m_exitCode = 5;
return false;
}
@@ -227,12 +231,13 @@ bool CApplication::Create()
if (! m_engine->Create() )
{
- SystemDialog( SDT_ERROR, "COLOBT - Fatal Error",
- std::string("Error in CEngine::Init()") );
- m_exitCode = 1;
+ m_errorMessage = std::string("Error in CEngine::Init()\n") + standardInfoMessage;
+ m_exitCode = 6;
return false;
}
+ GetLogger()->Info("CApplication created successfully\n");
+
return true;
}
@@ -241,10 +246,10 @@ bool CApplication::CreateVideoSurface()
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo == NULL)
{
- SystemDialog( SDT_ERROR, "COLOBOT - Fatal Error",
- std::string("SDL error while getting video info:\n ") +
- std::string(SDL_GetError()) );
- m_exitCode = 2;
+ m_errorMessage = std::string("SDL error while getting video info:\n ") +
+ std::string(SDL_GetError());
+ GetLogger()->Error(m_errorMessage.c_str());
+ m_exitCode = 7;
return false;
}
@@ -357,10 +362,11 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
{
if (! restore)
{
- SystemDialog( SDT_ERROR, "COLOBT - Error",
- std::string("SDL error while setting video mode:\n") +
+ std::string error = std::string("SDL error while setting video mode:\n") +
std::string(SDL_GetError()) + std::string("\n") +
- std::string("Previous mode will be restored") );
+ std::string("Previous mode will be restored");
+ GetLogger()->Error(error.c_str());
+ SystemDialog( SDT_ERROR, "COLOBT - Error", error);
restore = true;
ChangeVideoConfig(m_lastDeviceConfig);
@@ -370,9 +376,10 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
{
restore = false;
- SystemDialog( SDT_ERROR, "COLOBT - Fatal Error",
- std::string("SDL error while restoring previous video mode:\n") +
- std::string(SDL_GetError()) );
+ std::string error = std::string("SDL error while restoring previous video mode:\n") +
+ std::string(SDL_GetError());
+ GetLogger()->Error(error.c_str());
+ SystemDialog( SDT_ERROR, "COLOBT - Fatal Error", error);
// Fatal error, so post the quit event
@@ -598,6 +605,11 @@ int CApplication::GetExitCode()
return m_exitCode;
}
+const std::string& CApplication::GetErrorMessage()
+{
+ return m_errorMessage;
+}
+
//! Translates SDL press state to PressState
PressState TranslatePressState(unsigned char state)
{
diff --git a/src/app/app.h b/src/app/app.h
index 0cfaad2..7991177 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -131,6 +131,9 @@ public:
//! Returns the code to be returned at main() exit
int GetExitCode();
+ //! Returns the message of error (set to something if exit code is not 0)
+ const std::string& GetErrorMessage();
+
//! Cleans up before exit
void Destroy();
@@ -234,6 +237,9 @@ protected:
//! Whether debug mode is enabled
bool m_debugMode;
+ //! Message to be displayed as error to the user
+ std::string m_errorMessage;
+
//! Current configuration of OpenGL display device
Gfx::GLDeviceConfig m_deviceConfig;
//! Previous configuration of OpenGL display device
diff --git a/src/app/main.cpp b/src/app/main.cpp
index 619043e..0d885f7 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
if (! app.ParseArguments(argc, argv))
{
- SystemDialog(SDT_ERROR, "COLOBOT", "Invalid commandline arguments!\n");
+ SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n");
return app.GetExitCode();
}
@@ -90,6 +90,10 @@ int main(int argc, char *argv[])
{
app.Destroy(); // ensure a clean exit
code = app.GetExitCode();
+ if ( code != 0 && !app.GetErrorMessage().empty() )
+ {
+ SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app.GetErrorMessage());
+ }
logger.Info("Didn't run main loop. Exiting with code %d\n", code);
return code;
}