diff --git a/source/code/common.cpp b/source/code/common.cpp index f6f568e..99fa6ef 100644 --- a/source/code/common.cpp +++ b/source/code/common.cpp @@ -25,6 +25,7 @@ http://blockattack.net #include #include #include "os.hpp" +#include "sago/SagoMiscSdl2.hpp" using namespace std; using boost::format; @@ -52,8 +53,7 @@ bool strequals(const char* a, const char* b) { void dieOnNullptr(bool ptr, const char* msg) { if (!ptr) { - cerr << "Fatal error: " << msg << endl; - abort(); + sago::SagoFatalError(msg); } } diff --git a/source/code/sago/SagoMiscSdl2.cpp b/source/code/sago/SagoMiscSdl2.cpp new file mode 100644 index 0000000..e218775 --- /dev/null +++ b/source/code/sago/SagoMiscSdl2.cpp @@ -0,0 +1,45 @@ +/* + Copyright (c) 2016 Poul Sander + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#include "SagoMiscSdl2.hpp" +#include "SDL.h" + +void sago::SagoFatalError(const char* errorMsg) { + const SDL_MessageBoxButtonData buttons[] = { + { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Ok" }, + }; + const SDL_MessageBoxData messageboxdata = { + SDL_MESSAGEBOX_INFORMATION, /* .flags */ + nullptr, /* .window */ + "Fatal error", /* .title */ + errorMsg, /* .message */ + SDL_arraysize(buttons), /* .numbuttons */ + buttons, /* .buttons */ + nullptr /* .colorScheme */ + }; + int buttonid; + SDL_ShowMessageBox(&messageboxdata, &buttonid); + abort(); +} + diff --git a/source/code/sago/SagoMiscSdl2.hpp b/source/code/sago/SagoMiscSdl2.hpp new file mode 100644 index 0000000..90a4d69 --- /dev/null +++ b/source/code/sago/SagoMiscSdl2.hpp @@ -0,0 +1,35 @@ +/* + Copyright (c) 2016 Poul Sander + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, + publish, distribute, sublicense, and/or sell copies of the Software, + and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#ifndef SAGOMISCSDL2_HPP +#define SAGOMISCSDL2_HPP + +namespace sago { + + void SagoFatalError(const char* errorMsg); + +} + +#endif /* SAGOMISCSDL2_HPP */ +