diff --git a/source/main.c b/source/main.c index 194ed45..97bc821 100644 --- a/source/main.c +++ b/source/main.c @@ -11,37 +11,55 @@ int load_ctr_lib(lua_State *L); void unload_font_lib(); +bool errored, gfxinit = false; + // Display an error void error(const char *error) { - gfxInitDefault(); + if (!gfxinit) { + gfxInitDefault(); + } consoleInit(GFX_TOP, NULL); printf("------------------ FATAL ERROR -------------------"); printf(error); printf("\n--------------------------------------------------"); - printf("Please exit ctruLua by rebooting the console."); - + printf("Please exit ctruLua by pressing start."); + + errored = true; + while (aptMainLoop()) { + hidScanInput(); + if (hidKeysDown() & KEY_START) + break; gfxFlushBuffers(); gfxSwapBuffers(); gspWaitForVBlank(); } + if (!gfxinit) { + gfxExit(); + } } // Main loop int main() { + // Init Lua + lua_State *L = luaL_newstate(); + if (L == NULL) error("Memory allocation error while creating a new Lua state"); + if (errored) { + return 0; + } + // Init GFX sf2d_init(); sftd_init(); //sf2d_set_3d(true); + gfxinit = true; // Init accel/gyro HIDUSER_EnableAccelerometer(); HIDUSER_EnableGyroscope(); - // Init Lua - lua_State *L = luaL_newstate(); - if (L == NULL) error("Memory allocation error while creating a new Lua state"); + luaL_openlibs(L); load_ctr_lib(L); @@ -53,14 +71,14 @@ int main() { // Unload current font unload_font_lib(); - + // Disable accel/gyro HIDUSER_DisableAccelerometer(); HIDUSER_DisableGyroscope(); - + // Uninit GFX sftd_fini(); sf2d_fini(); - + return 0; }