diff --git a/source/main.c b/source/main.c index c7ae6ab..bb5e776 100644 --- a/source/main.c +++ b/source/main.c @@ -25,9 +25,9 @@ void cleanup() { soc_buffer = NULL; } + amExit(); ptmuExit(); acExit(); - amExit(); cfguExit(); romfsExit(); gfxExit(); @@ -49,7 +49,7 @@ int main(int argc, const char* argv[]) { aptCloseSession(); if(R_FAILED(setCpuTimeRes)) { - util_panic("Failed to set syscore CPU time: %08lX", setCpuTimeRes); + util_panic("Failed to set syscore CPU time limit: %08lX", setCpuTimeRes); return 1; } @@ -71,12 +71,8 @@ int main(int argc, const char* argv[]) { mainmenu_open(); - while(aptMainLoop()) { + while(aptMainLoop() && ui_top() != NULL) { ui_update(); - if(ui_peek() == NULL) { - break; - } - ui_draw(); } diff --git a/source/ui/mainmenu.c b/source/ui/mainmenu.c index 0752f29..5e4b662 100644 --- a/source/ui/mainmenu.c +++ b/source/ui/mainmenu.c @@ -51,6 +51,7 @@ static void mainmenu_update(ui_view* view, void* data, list_item** items, u32** if(hidKeysDown() & KEY_START) { ui_pop(); list_destroy(view); + return; } diff --git a/source/ui/section/action/launchtitle.c b/source/ui/section/action/launchtitle.c index c741aa9..d6e0593 100644 --- a/source/ui/section/action/launchtitle.c +++ b/source/ui/section/action/launchtitle.c @@ -9,26 +9,20 @@ static void action_launch_title_update(ui_view* view, void* data, float* progress, char* text) { title_info* info = (title_info*) data; - u8 buf0[0x300]; - u8 buf1[0x20]; - Result res = 0; aptOpenSession(); if(R_SUCCEEDED(res = APT_PrepareToDoAppJump(0, info->titleId, info->mediaType))) { + u8 buf0[0x300]; + u8 buf1[0x20]; + res = APT_DoAppJump(0x300, 0x20, buf0, buf1); } aptCloseSession(); - info_destroy(view); - - if(R_SUCCEEDED(res)) { - while(ui_peek() != NULL) { - ui_pop(); - } - } else { + if(R_FAILED(res)) { ui_pop(); info_destroy(view); diff --git a/source/ui/ui.c b/source/ui/ui.c index 3113895..9354ff8 100644 --- a/source/ui/ui.c +++ b/source/ui/ui.c @@ -28,6 +28,19 @@ void ui_exit() { } } +ui_view* ui_top() { + svcWaitSynchronization(ui_stack_mutex, U64_MAX); + + ui_view* ui = NULL; + if(ui_stack_top >= 0) { + ui = ui_stack[ui_stack_top]; + } + + svcReleaseMutex(ui_stack_mutex); + + return ui; +} + bool ui_push(ui_view* view) { if(view == NULL) { return false; @@ -35,50 +48,30 @@ bool ui_push(ui_view* view) { svcWaitSynchronization(ui_stack_mutex, U64_MAX); - if(ui_stack_top >= MAX_UI_VIEWS - 1) { - return false; + bool space = ui_stack_top < MAX_UI_VIEWS - 1; + if(space) { + ui_stack[++ui_stack_top] = view; } - ui_stack[++ui_stack_top] = view; - svcReleaseMutex(ui_stack_mutex); - return true; + return space; } -ui_view* ui_peek() { +void ui_pop() { svcWaitSynchronization(ui_stack_mutex, U64_MAX); - if(ui_stack_top == -1) { - return NULL; + if(ui_stack_top >= 0) { + ui_stack[ui_stack_top--] = NULL; } - - ui_view* ui = ui_stack[ui_stack_top]; - + svcReleaseMutex(ui_stack_mutex); - - return ui; -} - -ui_view* ui_pop() { - svcWaitSynchronization(ui_stack_mutex, U64_MAX); - - if(ui_stack_top == -1) { - return NULL; - } - - ui_view* view = ui_stack[ui_stack_top]; - ui_stack[ui_stack_top--] = NULL; - - svcReleaseMutex(ui_stack_mutex); - - return view; } void ui_update() { hidScanInput(); - ui_view* ui = ui_peek(); + ui_view* ui = ui_top(); if(ui != NULL && ui->update != NULL) { u32 bottomScreenTopBarHeight = 0; screen_get_texture_size(NULL, &bottomScreenTopBarHeight, TEXTURE_BOTTOM_SCREEN_TOP_BAR); @@ -240,7 +233,7 @@ static void ui_draw_bottom(ui_view* ui) { } void ui_draw() { - ui_view* ui = ui_peek(); + ui_view* ui = ui_top(); if(ui != NULL) { screen_begin_frame(); ui_draw_top(ui); diff --git a/source/ui/ui.h b/source/ui/ui.h index 6648b15..d0ee4ba 100644 --- a/source/ui/ui.h +++ b/source/ui/ui.h @@ -14,9 +14,9 @@ typedef struct ui_view_s { void ui_init(); void ui_exit(); +ui_view* ui_top(); bool ui_push(ui_view* view); -ui_view* ui_peek(); -ui_view* ui_pop(); +void ui_pop(); void ui_update(); void ui_draw();