summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichał Konopacki <konopacki.m@gmail.com>2012-08-13 23:46:47 +0200
committerMichał Konopacki <konopacki.m@gmail.com>2012-08-13 23:46:47 +0200
commite942400c8bb9b6836bdfe705111f7ec63ef19e28 (patch)
tree66d5aea574f5a4530492b6ab69956003427df98b /src
parent9ee1d2e172162be25b113595ad16779aa0a49a87 (diff)
parent8b2bca72dd71a1c23db51269a147443c80758f10 (diff)
downloadcolobot-e942400c8bb9b6836bdfe705111f7ec63ef19e28.tar.gz
colobot-e942400c8bb9b6836bdfe705111f7ec63ef19e28.tar.bz2
colobot-e942400c8bb9b6836bdfe705111f7ec63ef19e28.zip
Merge remote-tracking branch 'upstream/dev-ui' into dev-ui
Diffstat (limited to 'src')
-rw-r--r--src/app/app.cpp64
-rw-r--r--src/app/app.h6
-rw-r--r--src/app/main.cpp6
-rw-r--r--src/graphics/core/device.h3
-rw-r--r--src/graphics/engine/engine.cpp7
-rw-r--r--src/graphics/opengl/gldevice.cpp16
-rw-r--r--src/graphics/opengl/gldevice.h4
7 files changed, 59 insertions, 47 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;
}
diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h
index a3d0208..9eb6f6d 100644
--- a/src/graphics/core/device.h
+++ b/src/graphics/core/device.h
@@ -286,9 +286,6 @@ public:
//! Destroys the device, releasing every acquired resource
virtual void Destroy() = 0;
- //! Returns the last encountered error
- virtual std::string GetError() = 0;
-
//! Begins drawing the 3D scene
virtual void BeginScene() = 0;
//! Ends drawing the 3D scene
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 5988949..3187dde 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -2113,8 +2113,7 @@ Gfx::Texture Gfx::CEngine::CreateTexture(const std::string& texName, const Gfx::
if (! img.Load(m_app->GetDataFilePath(m_texPath, texName)))
{
std::string error = img.GetError();
- GetLogger()->Error("Couldn't load texture '%s': %s\n", texName.c_str(), error.c_str());
- GetLogger()->Error("Blacklisting texture '%s'\n", texName.c_str());
+ GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str());
m_texBlacklist.insert(texName);
return Gfx::Texture(); // invalid texture
}
@@ -2123,9 +2122,7 @@ Gfx::Texture Gfx::CEngine::CreateTexture(const std::string& texName, const Gfx::
if (! tex.Valid())
{
- std::string error = m_device->GetError();
- GetLogger()->Error("Couldn't load texture '%s': %s\n", texName.c_str(), error.c_str());
- GetLogger()->Error("Blacklisting texture '%s'\n", texName.c_str());
+ GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str());
m_texBlacklist.insert(texName);
return tex;
}
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index 3526b13..7221421 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -20,6 +20,7 @@
#include "common/config.h"
#include "common/image.h"
+#include "common/logger.h"
#include "math/geometry.h"
@@ -80,13 +81,10 @@ void Gfx::CGLDevice::DebugHook()
glColor3i(0, 0, 0);
}
-std::string Gfx::CGLDevice::GetError()
-{
- return m_error;
-}
-
bool Gfx::CGLDevice::Create()
{
+ GetLogger()->Info("Creating CDevice\n");
+
#if defined(USE_GLEW)
static bool glewInited = false;
@@ -96,13 +94,13 @@ bool Gfx::CGLDevice::Create()
if (glewInit() != GLEW_OK)
{
- m_error = "GLEW initialization failed";
+ GetLogger()->Error("GLEW initialization failed\n");
return false;
}
if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) || (! GLEW_EXT_secondary_color) )
{
- m_error = "GLEW reports required extensions not supported";
+ GetLogger()->Error("GLEW reports required extensions not supported\n");
return false;
}
}
@@ -142,6 +140,8 @@ bool Gfx::CGLDevice::Create()
m_texturesEnabled = std::vector<bool> (maxTextures, false);
m_textureStageParams = std::vector<Gfx::TextureStageParams>(maxTextures, Gfx::TextureStageParams());
+ GetLogger()->Info("CDevice created successfully\n");
+
return true;
}
@@ -385,7 +385,7 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCrea
ImageData *data = image->GetData();
if (data == NULL)
{
- m_error = "Invalid texture data";
+ GetLogger()->Error("Invalid texture data\n");
return Gfx::Texture(); // invalid texture
}
diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h
index 3daea8a..b59af1c 100644
--- a/src/graphics/opengl/gldevice.h
+++ b/src/graphics/opengl/gldevice.h
@@ -78,8 +78,6 @@ public:
virtual void DebugHook();
- virtual std::string GetError();
-
virtual bool Create();
virtual void Destroy();
@@ -169,8 +167,6 @@ private:
private:
//! Current config
Gfx::GLDeviceConfig m_config;
- //! Last encountered error
- std::string m_error;
//! Current world matrix
Math::Matrix m_worldMat;