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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue