1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-28 00:39:30 +00:00

Some enhancements in case of error, should fix some things on hardware.

This commit is contained in:
Firew0lf 2015-08-19 23:07:43 +02:00
parent ebd3a6804d
commit 94d69c646c

View file

@ -11,37 +11,55 @@
int load_ctr_lib(lua_State *L); int load_ctr_lib(lua_State *L);
void unload_font_lib(); void unload_font_lib();
bool errored, gfxinit = false;
// Display an error // Display an error
void error(const char *error) { void error(const char *error) {
gfxInitDefault(); if (!gfxinit) {
gfxInitDefault();
}
consoleInit(GFX_TOP, NULL); consoleInit(GFX_TOP, NULL);
printf("------------------ FATAL ERROR -------------------"); printf("------------------ FATAL ERROR -------------------");
printf(error); printf(error);
printf("\n--------------------------------------------------"); printf("\n--------------------------------------------------");
printf("Please exit ctruLua by rebooting the console."); printf("Please exit ctruLua by pressing start.");
errored = true;
while (aptMainLoop()) { while (aptMainLoop()) {
hidScanInput();
if (hidKeysDown() & KEY_START)
break;
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gspWaitForVBlank(); gspWaitForVBlank();
} }
if (!gfxinit) {
gfxExit();
}
} }
// Main loop // Main loop
int main() { 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 // Init GFX
sf2d_init(); sf2d_init();
sftd_init(); sftd_init();
//sf2d_set_3d(true); //sf2d_set_3d(true);
gfxinit = true;
// Init accel/gyro // Init accel/gyro
HIDUSER_EnableAccelerometer(); HIDUSER_EnableAccelerometer();
HIDUSER_EnableGyroscope(); 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); luaL_openlibs(L);
load_ctr_lib(L); load_ctr_lib(L);
@ -53,14 +71,14 @@ int main() {
// Unload current font // Unload current font
unload_font_lib(); unload_font_lib();
// Disable accel/gyro // Disable accel/gyro
HIDUSER_DisableAccelerometer(); HIDUSER_DisableAccelerometer();
HIDUSER_DisableGyroscope(); HIDUSER_DisableGyroscope();
// Uninit GFX // Uninit GFX
sftd_fini(); sftd_fini();
sf2d_fini(); sf2d_fini();
return 0; return 0;
} }