Improved error messages
Added some logging and improved error messages displayed to userdev-ui
parent
a2dd39960b
commit
5b45911856
|
@ -149,6 +149,8 @@ bool CApplication::ParseArguments(int argc, char *argv[])
|
||||||
|
|
||||||
bool CApplication::Create()
|
bool CApplication::Create()
|
||||||
{
|
{
|
||||||
|
GetLogger()->Info("Creating CApplication\n");
|
||||||
|
|
||||||
// TODO: verify that data directory exists
|
// TODO: verify that data directory exists
|
||||||
|
|
||||||
// Temporarily -- only in windowed mode
|
// Temporarily -- only in windowed mode
|
||||||
|
@ -161,6 +163,9 @@ bool CApplication::Create()
|
||||||
m_robotMain = new CRobotMain(m_iMan); */
|
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 */
|
/* SDL initialization sequence */
|
||||||
|
|
||||||
|
@ -169,18 +174,18 @@ bool CApplication::Create()
|
||||||
|
|
||||||
if (SDL_Init(initFlags) < 0)
|
if (SDL_Init(initFlags) < 0)
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBOT - Fatal Error",
|
m_errorMessage = std::string("SDL initialization error:\n") +
|
||||||
"SDL initialization error:\n" +
|
std::string(SDL_GetError());
|
||||||
std::string(SDL_GetError()) );
|
GetLogger()->Error(m_errorMessage.c_str());
|
||||||
m_exitCode = 2;
|
m_exitCode = 2;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0)
|
if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0)
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBOT - Fatal Error",
|
m_errorMessage = std::string("SDL_Image initialization error:\n") +
|
||||||
std::string("SDL_Image initialization error:\n") +
|
std::string(IMG_GetError());
|
||||||
std::string(IMG_GetError()) );
|
GetLogger()->Error(m_errorMessage.c_str());
|
||||||
m_exitCode = 3;
|
m_exitCode = 3;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -190,10 +195,10 @@ bool CApplication::Create()
|
||||||
|
|
||||||
if (m_private->surface == NULL)
|
if (m_private->surface == NULL)
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBT - Fatal Error",
|
m_errorMessage = std::string("SDL error while setting video mode:\n") +
|
||||||
std::string("SDL error while setting video mode:\n") +
|
std::string(SDL_GetError());
|
||||||
std::string(SDL_GetError()) );
|
GetLogger()->Error(m_errorMessage.c_str());
|
||||||
m_exitCode = 2;
|
m_exitCode = 4;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,9 +219,8 @@ bool CApplication::Create()
|
||||||
m_device = new Gfx::CGLDevice(m_deviceConfig);
|
m_device = new Gfx::CGLDevice(m_deviceConfig);
|
||||||
if (! m_device->Create() )
|
if (! m_device->Create() )
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBT - Fatal Error",
|
m_errorMessage = std::string("Error in CDevice::Create()\n") + standardInfoMessage;
|
||||||
std::string("Error in CDevice::Create()") );
|
m_exitCode = 5;
|
||||||
m_exitCode = 1;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,12 +231,13 @@ bool CApplication::Create()
|
||||||
|
|
||||||
if (! m_engine->Create() )
|
if (! m_engine->Create() )
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBT - Fatal Error",
|
m_errorMessage = std::string("Error in CEngine::Init()\n") + standardInfoMessage;
|
||||||
std::string("Error in CEngine::Init()") );
|
m_exitCode = 6;
|
||||||
m_exitCode = 1;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetLogger()->Info("CApplication created successfully\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,10 +246,10 @@ bool CApplication::CreateVideoSurface()
|
||||||
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
|
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
|
||||||
if (videoInfo == NULL)
|
if (videoInfo == NULL)
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBOT - Fatal Error",
|
m_errorMessage = std::string("SDL error while getting video info:\n ") +
|
||||||
std::string("SDL error while getting video info:\n ") +
|
std::string(SDL_GetError());
|
||||||
std::string(SDL_GetError()) );
|
GetLogger()->Error(m_errorMessage.c_str());
|
||||||
m_exitCode = 2;
|
m_exitCode = 7;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,10 +362,11 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
|
||||||
{
|
{
|
||||||
if (! restore)
|
if (! restore)
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBT - Error",
|
std::string error = std::string("SDL error while setting video mode:\n") +
|
||||||
std::string("SDL error while setting video mode:\n") +
|
|
||||||
std::string(SDL_GetError()) + std::string("\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;
|
restore = true;
|
||||||
ChangeVideoConfig(m_lastDeviceConfig);
|
ChangeVideoConfig(m_lastDeviceConfig);
|
||||||
|
@ -370,9 +376,10 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
|
||||||
{
|
{
|
||||||
restore = false;
|
restore = false;
|
||||||
|
|
||||||
SystemDialog( SDT_ERROR, "COLOBT - Fatal Error",
|
std::string error = std::string("SDL error while restoring previous video mode:\n") +
|
||||||
std::string("SDL error while restoring previous video mode:\n") +
|
std::string(SDL_GetError());
|
||||||
std::string(SDL_GetError()) );
|
GetLogger()->Error(error.c_str());
|
||||||
|
SystemDialog( SDT_ERROR, "COLOBT - Fatal Error", error);
|
||||||
|
|
||||||
|
|
||||||
// Fatal error, so post the quit event
|
// Fatal error, so post the quit event
|
||||||
|
@ -598,6 +605,11 @@ int CApplication::GetExitCode()
|
||||||
return m_exitCode;
|
return m_exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& CApplication::GetErrorMessage()
|
||||||
|
{
|
||||||
|
return m_errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
//! Translates SDL press state to PressState
|
//! Translates SDL press state to PressState
|
||||||
PressState TranslatePressState(unsigned char state)
|
PressState TranslatePressState(unsigned char state)
|
||||||
{
|
{
|
||||||
|
|
|
@ -131,6 +131,9 @@ public:
|
||||||
//! Returns the code to be returned at main() exit
|
//! Returns the code to be returned at main() exit
|
||||||
int GetExitCode();
|
int GetExitCode();
|
||||||
|
|
||||||
|
//! Returns the message of error (set to something if exit code is not 0)
|
||||||
|
const std::string& GetErrorMessage();
|
||||||
|
|
||||||
//! Cleans up before exit
|
//! Cleans up before exit
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
|
@ -234,6 +237,9 @@ protected:
|
||||||
//! Whether debug mode is enabled
|
//! Whether debug mode is enabled
|
||||||
bool m_debugMode;
|
bool m_debugMode;
|
||||||
|
|
||||||
|
//! Message to be displayed as error to the user
|
||||||
|
std::string m_errorMessage;
|
||||||
|
|
||||||
//! Current configuration of OpenGL display device
|
//! Current configuration of OpenGL display device
|
||||||
Gfx::GLDeviceConfig m_deviceConfig;
|
Gfx::GLDeviceConfig m_deviceConfig;
|
||||||
//! Previous configuration of OpenGL display device
|
//! Previous configuration of OpenGL display device
|
||||||
|
|
|
@ -80,7 +80,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
if (! app.ParseArguments(argc, 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();
|
return app.GetExitCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +90,10 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
app.Destroy(); // ensure a clean exit
|
app.Destroy(); // ensure a clean exit
|
||||||
code = app.GetExitCode();
|
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);
|
logger.Info("Didn't run main loop. Exiting with code %d\n", code);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,9 +286,6 @@ public:
|
||||||
//! Destroys the device, releasing every acquired resource
|
//! Destroys the device, releasing every acquired resource
|
||||||
virtual void Destroy() = 0;
|
virtual void Destroy() = 0;
|
||||||
|
|
||||||
//! Returns the last encountered error
|
|
||||||
virtual std::string GetError() = 0;
|
|
||||||
|
|
||||||
//! Begins drawing the 3D scene
|
//! Begins drawing the 3D scene
|
||||||
virtual void BeginScene() = 0;
|
virtual void BeginScene() = 0;
|
||||||
//! Ends drawing the 3D scene
|
//! Ends drawing the 3D scene
|
||||||
|
|
|
@ -2113,8 +2113,7 @@ Gfx::Texture Gfx::CEngine::CreateTexture(const std::string& texName, const Gfx::
|
||||||
if (! img.Load(m_app->GetDataFilePath(m_texPath, texName)))
|
if (! img.Load(m_app->GetDataFilePath(m_texPath, texName)))
|
||||||
{
|
{
|
||||||
std::string error = img.GetError();
|
std::string error = img.GetError();
|
||||||
GetLogger()->Error("Couldn't load texture '%s': %s\n", texName.c_str(), error.c_str());
|
GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str());
|
||||||
GetLogger()->Error("Blacklisting texture '%s'\n", texName.c_str());
|
|
||||||
m_texBlacklist.insert(texName);
|
m_texBlacklist.insert(texName);
|
||||||
return Gfx::Texture(); // invalid texture
|
return Gfx::Texture(); // invalid texture
|
||||||
}
|
}
|
||||||
|
@ -2123,9 +2122,7 @@ Gfx::Texture Gfx::CEngine::CreateTexture(const std::string& texName, const Gfx::
|
||||||
|
|
||||||
if (! tex.Valid())
|
if (! tex.Valid())
|
||||||
{
|
{
|
||||||
std::string error = m_device->GetError();
|
GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str());
|
||||||
GetLogger()->Error("Couldn't load texture '%s': %s\n", texName.c_str(), error.c_str());
|
|
||||||
GetLogger()->Error("Blacklisting texture '%s'\n", texName.c_str());
|
|
||||||
m_texBlacklist.insert(texName);
|
m_texBlacklist.insert(texName);
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
#include "common/image.h"
|
#include "common/image.h"
|
||||||
|
#include "common/logger.h"
|
||||||
#include "math/geometry.h"
|
#include "math/geometry.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,13 +81,10 @@ void Gfx::CGLDevice::DebugHook()
|
||||||
glColor3i(0, 0, 0);
|
glColor3i(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Gfx::CGLDevice::GetError()
|
|
||||||
{
|
|
||||||
return m_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Gfx::CGLDevice::Create()
|
bool Gfx::CGLDevice::Create()
|
||||||
{
|
{
|
||||||
|
GetLogger()->Info("Creating CDevice\n");
|
||||||
|
|
||||||
#if defined(USE_GLEW)
|
#if defined(USE_GLEW)
|
||||||
static bool glewInited = false;
|
static bool glewInited = false;
|
||||||
|
|
||||||
|
@ -96,13 +94,13 @@ bool Gfx::CGLDevice::Create()
|
||||||
|
|
||||||
if (glewInit() != GLEW_OK)
|
if (glewInit() != GLEW_OK)
|
||||||
{
|
{
|
||||||
m_error = "GLEW initialization failed";
|
GetLogger()->Error("GLEW initialization failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) || (! GLEW_EXT_secondary_color) )
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +140,8 @@ bool Gfx::CGLDevice::Create()
|
||||||
m_texturesEnabled = std::vector<bool> (maxTextures, false);
|
m_texturesEnabled = std::vector<bool> (maxTextures, false);
|
||||||
m_textureStageParams = std::vector<Gfx::TextureStageParams>(maxTextures, Gfx::TextureStageParams());
|
m_textureStageParams = std::vector<Gfx::TextureStageParams>(maxTextures, Gfx::TextureStageParams());
|
||||||
|
|
||||||
|
GetLogger()->Info("CDevice created successfully\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCrea
|
||||||
ImageData *data = image->GetData();
|
ImageData *data = image->GetData();
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
{
|
{
|
||||||
m_error = "Invalid texture data";
|
GetLogger()->Error("Invalid texture data\n");
|
||||||
return Gfx::Texture(); // invalid texture
|
return Gfx::Texture(); // invalid texture
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,8 +78,6 @@ public:
|
||||||
|
|
||||||
virtual void DebugHook();
|
virtual void DebugHook();
|
||||||
|
|
||||||
virtual std::string GetError();
|
|
||||||
|
|
||||||
virtual bool Create();
|
virtual bool Create();
|
||||||
virtual void Destroy();
|
virtual void Destroy();
|
||||||
|
|
||||||
|
@ -169,8 +167,6 @@ private:
|
||||||
private:
|
private:
|
||||||
//! Current config
|
//! Current config
|
||||||
Gfx::GLDeviceConfig m_config;
|
Gfx::GLDeviceConfig m_config;
|
||||||
//! Last encountered error
|
|
||||||
std::string m_error;
|
|
||||||
|
|
||||||
//! Current world matrix
|
//! Current world matrix
|
||||||
Math::Matrix m_worldMat;
|
Math::Matrix m_worldMat;
|
||||||
|
|
Loading…
Reference in New Issue