Skip to content

Commit

Permalink
Some enhancements in case of error, should fix some things on hardware.
Browse files Browse the repository at this point in the history
  • Loading branch information
firew0lf committed Aug 19, 2015
1 parent ebd3a68 commit 94d69c6
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions source/main.c
Expand Up @@ -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);

Expand All @@ -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;
}

0 comments on commit 94d69c6

Please sign in to comment.