sdl: do not change workdir on developer builds

show message box on fatal errors
This commit is contained in:
Jakub Czekański 2019-08-16 02:58:22 +02:00
parent 3a5fe8ce09
commit 73977d2586
2 changed files with 29 additions and 12 deletions

View file

@ -3,7 +3,11 @@ function generateVersionFile()
local branch = getSingleLineOutput('git symbolic-ref --short -q HEAD')
local commit = getSingleLineOutput('git rev-parse --short=7 HEAD')
local date = os.date("!%Y-%m-%d %H:%M:%S")
local releaseBuild = false
if os.getenv("CI") ~= nil then
releaseBuild = true
end
if os.getenv("APPVEYOR") == "True" then
branch = os.getenv("APPVEYOR_REPO_BRANCH")
end
@ -28,6 +32,9 @@ function generateVersionFile()
f:write(string.format('#define BUILD_COMMIT "%s"\n', commit))
f:write(string.format('#define BUILD_DATE "%s"\n', date))
f:write(string.format('#define BUILD_STRING "%s"\n', versionString))
if releaseBuild == true then
f:write('#define BUILD_IS_RELEASE true\n')
end
f:close()
end

View file

@ -224,23 +224,33 @@ void limitFramerate(std::unique_ptr<System>& sys, SDL_Window* window, bool frame
}
}
int main(int argc, char** argv) {
void fatalError(const std::string& error) {
fprintf(stderr, "[FATAL] %s", error.c_str());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Avocado", error.c_str(), nullptr);
}
void changeWorkingDirectory() {
std::string workingDirectory = ".";
#ifdef ANDROID
workingDirectory = "/sdcard/avocado"; // TODO: Use Envoiroment.getExternalStorageDirectory();
// TODO: Use Envoiroment.getExternalStorageDirectory();
workingDirectory = "/sdcard/avocado";
#else
{
char* basePath = SDL_GetBasePath();
workingDirectory = basePath;
SDL_free(basePath);
}
char* basePath = SDL_GetBasePath();
workingDirectory = basePath;
SDL_free(basePath);
#endif
chdir(workingDirectory.c_str());
}
int main(int argc, char** argv) {
#ifdef BUILD_IS_RELEASE
changeWorkingDirectory();
#endif
loadConfigFile(CONFIG_NAME);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) != 0) {
printf("Cannot init SDL (%s)\n", SDL_GetError());
fatalError(string_format("Cannot init SDL (%s)", SDL_GetError()));
return 1;
}
@ -248,25 +258,25 @@ int main(int argc, char** argv) {
OpenGL opengl;
if (!opengl.init()) {
printf("Cannot initialize OpenGL\n");
fatalError("Cannot initialize OpenGL");
return 1;
}
SDL_Window* window = SDL_CreateWindow("Avocado", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, OpenGL::resWidth, OpenGL::resHeight,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI);
if (window == nullptr) {
printf("Cannot create window (%s)\n", SDL_GetError());
fatalError(string_format("Cannot create window (%s)", SDL_GetError()));
return 1;
}
SDL_GLContext glContext = SDL_GL_CreateContext(window);
if (glContext == nullptr) {
printf("Cannot create OpenGL context (%s)\n", SDL_GetError());
fatalError(string_format("Cannot create OpenGL context (%s)", SDL_GetError()));
return 1;
}
if (!opengl.setup()) {
printf("Cannot setup graphics\n");
fatalError("Cannot setup graphics");
return 1;
}