1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +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);
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;
}