commit c3fc09e9
A formatted error message
Changed files
| M | source/code/main.cpp before |
| M | source/code/sago/SagoDataHolder.cpp before |
| M | source/code/sago/SagoMiscSdl2.cpp before |
| M | source/code/sago/SagoMiscSdl2.hpp before |
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 8b2a6b8..dc22901 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -565,6 +565,7 @@ static textManeger theTextManeger;
#include "BlockGame.hpp"
#include "BlockGame.cpp"
#include "os.hpp"
+#include "sago/SagoMiscSdl2.hpp"
class BlockGameSdl : public BlockGame {
public:
@@ -1793,6 +1794,7 @@ static void StartTwoPlayerVs() {
//The main function, quite big... too big
int main(int argc, char* argv[]) {
+ try {
OsCreateFolders();
highPriority = false; //if true the game will take most resources, but increase framerate.
bFullscreen = false;
@@ -2122,6 +2124,10 @@ int main(int argc, char* argv[]) {
//Close file system Apstraction layer!
PHYSFS_deinit();
+
+ } catch (exception& e) {
+ sago::SagoFatalError(e.what());
+ }
return 0;
}
diff --git a/source/code/sago/SagoDataHolder.cpp b/source/code/sago/SagoDataHolder.cpp
index da774d9..516cdef 100644
--- a/source/code/sago/SagoDataHolder.cpp
+++ b/source/code/sago/SagoDataHolder.cpp
@@ -30,6 +30,7 @@
#include <physfs.h>
#include <memory>
#include <SDL_mixer.h>
+#include "SagoMiscSdl2.hpp"
namespace sago {
@@ -84,13 +85,10 @@ SDL_Texture* SagoDataHolder::getTexturePtr(const std::string& textureName) const
printFileWeLoad(path);
}
if (!PHYSFS_exists(path.c_str())) {
- std::cerr << "getTextureFailed - Texture does not exists: " << path << std::endl;
- exit(1);
- return ret;
+ sago::SagoFatalErrorF("getTextureFailed - Texture does not exist: %s", path.c_str());
}
PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
unsigned int m_size = PHYSFS_fileLength(myfile);
- //char* m_data = new char[m_size];
std::unique_ptr<char[]> m_data(new char[m_size]);
int length_read = PHYSFS_read (myfile, m_data.get(), 1, m_size);
if (length_read != (int)m_size) {
@@ -152,7 +150,6 @@ TTF_Font* SagoDataHolder::getFontPtr(const std::string& fontName, int ptsize) co
}
ret = TTF_OpenFontRW(rw, SDL_FALSE, ptsize);
- //delete [] m_data;
if (!ret) {
std::cerr << "Error openening font: " << fontName << " because: " << TTF_GetError() << std::endl;
}
diff --git a/source/code/sago/SagoMiscSdl2.cpp b/source/code/sago/SagoMiscSdl2.cpp
index e218775..ce11f8b 100644
--- a/source/code/sago/SagoMiscSdl2.cpp
+++ b/source/code/sago/SagoMiscSdl2.cpp
@@ -43,3 +43,11 @@ void sago::SagoFatalError(const char* errorMsg) {
abort();
}
+void sago::SagoFatalErrorF(const char* fmt, ...) {
+ char buffer[1024];
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(buffer, sizeof(buffer), fmt, args);
+ SagoFatalError(buffer);
+ va_end(args);
+}
\ No newline at end of file
diff --git a/source/code/sago/SagoMiscSdl2.hpp b/source/code/sago/SagoMiscSdl2.hpp
index 90a4d69..1dac489 100644
--- a/source/code/sago/SagoMiscSdl2.hpp
+++ b/source/code/sago/SagoMiscSdl2.hpp
@@ -28,6 +28,7 @@
namespace sago {
void SagoFatalError(const char* errorMsg);
+ void SagoFatalErrorF(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
}