Skip to content
Permalink
Browse files

sdl: do not change workdir on developer builds

show message box on fatal errors
  • Loading branch information
JaCzekanski committed Aug 16, 2019
1 parent 3a5fe8c commit 73977d2586540552befa7243a75e95a35be5bf06
Showing with 29 additions and 12 deletions.
  1. +7 −0 premake/tools.lua
  2. +22 −12 src/platform/windows/main.cpp
@@ -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

@@ -224,49 +224,59 @@ 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;
}

SDL_GameControllerAddMappingsFromFile("data/assets/gamecontrollerdb.txt");

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;
}

0 comments on commit 73977d2

Please sign in to comment.
You can’t perform that action at this time.