From: notaz Date: Wed, 30 Jan 2013 01:55:15 +0000 (+0200) Subject: frontend: change how exit is done X-Git-Tag: r19~25 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=commitdiff_plain;h=69e482e3def6669a4fa921d07f9ba04883d7de34 frontend: change how exit is done will no longer be done from recompiler callback that could cause still used data to be freed --- diff --git a/frontend/libpicofe b/frontend/libpicofe index 215e7ed2..63f173a2 160000 --- a/frontend/libpicofe +++ b/frontend/libpicofe @@ -1 +1 @@ -Subproject commit 215e7ed2510e191664b611a578ffb987cf4fdab3 +Subproject commit 63f173a2509a27f9ae156ad6ee798d76dec0ad6b diff --git a/frontend/main.c b/frontend/main.c index 0f0e641b..df2af8f2 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -50,7 +50,7 @@ extern int iUseInterpolation; extern int iXAPitch; extern int iVolume; -int ready_to_go, g_resetting; +int ready_to_go, g_emu_want_quit, g_emu_resetting; unsigned long gpuDisp; char cfgfile_basename[MAXPATHLEN]; int state_slot; @@ -437,6 +437,12 @@ int emu_core_init(void) return 0; } +void emu_core_ask_exit(void) +{ + stop = 1; + g_emu_want_quit = 1; +} + #ifndef NO_FRONTEND static void create_profile_dir(const char *directory) { char path[MAXPATHLEN]; @@ -622,7 +628,7 @@ int main(int argc, char *argv[]) pl_start_watchdog(); - while (1) + while (!g_emu_want_quit) { stop = 0; emu_action = SACTION_NONE; @@ -632,6 +638,12 @@ int main(int argc, char *argv[]) do_emu_action(); } + printf("Exit..\n"); + ClosePlugins(); + SysClose(); + menu_finish(); + plat_finish(); + return 0; } @@ -684,7 +696,7 @@ void SysReset() { // so we need to prevent updateLace() call.. void *real_lace = GPU_updateLace; GPU_updateLace = dummy_lace; - g_resetting = 1; + g_emu_resetting = 1; // reset can run code, timing must be set pl_timing_prepare(Config.PsxType); @@ -695,7 +707,7 @@ void SysReset() { CDR_stop(); GPU_updateLace = real_lace; - g_resetting = 0; + g_emu_resetting = 0; } void SysClose() { @@ -704,22 +716,15 @@ void SysClose() { StopDebugger(); - if (emuLog != NULL) fclose(emuLog); + if (emuLog != NULL && emuLog != stdout && emuLog != stderr) { + fclose(emuLog); + emuLog = NULL; + } } void SysUpdate() { } -void OnFile_Exit() { - printf("OnFile_Exit\n"); - SysClose(); -#ifndef NO_FRONTEND - menu_finish(); - plat_finish(); - exit(0); -#endif -} - int get_state_filename(char *buf, int size, int i) { return get_gameid_filename(buf, size, "." STATES_DIR "%.32s-%.9s.%3.3d", i); @@ -809,8 +814,7 @@ void SysMessage(const char *fmt, ...) { } static void SignalExit(int sig) { - ClosePlugins(); - OnFile_Exit(); + emu_core_ask_exit(); } #define PARSEPATH(dst, src) \ diff --git a/frontend/main.h b/frontend/main.h index d9718906..7ce9e5d6 100644 --- a/frontend/main.h +++ b/frontend/main.h @@ -16,8 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA */ -#ifndef __LINUX_H__ -#define __LINUX_H__ +#ifndef __FRONTEND_MAIN_H__ +#define __FRONTEND_MAIN_H__ #include "config.h" @@ -41,6 +41,8 @@ extern int state_slot; int emu_core_preinit(void); int emu_core_init(void); +void emu_core_ask_exit(void); + void emu_set_default_config(void); void emu_on_new_cd(int show_hud_msg); @@ -52,7 +54,7 @@ int emu_load_state(int slot); void set_cd_image(const char *fname); extern unsigned long gpuDisp; -extern int ready_to_go, g_resetting; +extern int ready_to_go, g_emu_want_quit, g_emu_resetting; extern char hud_msg[64]; extern int hud_new_msg; @@ -68,7 +70,7 @@ enum sched_action { SACTION_SWITCH_DISPMODE, SACTION_FAST_FORWARD, SACTION_SCREENSHOT, - SACTION_VOLUME_UP, + SACTION_VOLUME_UP, // 10 SACTION_VOLUME_DOWN, SACTION_MINIMIZE, SACTION_TOGGLE_FPS, @@ -93,4 +95,4 @@ static inline void emu_set_action(enum sched_action action_) emu_action = action_; } -#endif /* __LINUX_H__ */ +#endif /* __FRONTEND_MAIN_H__ */ diff --git a/frontend/menu.c b/frontend/menu.c index 81195051..b25e1927 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -1832,7 +1832,6 @@ static void menu_bios_warn(void) // ------------ main menu ------------ static menu_entry e_menu_main[]; -void OnFile_Exit(); static void draw_frame_main(void) { @@ -2153,8 +2152,8 @@ static int main_menu_handler(int id, int keys) in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70); break; case MA_MAIN_EXIT: - OnFile_Exit(); - break; + emu_core_ask_exit(); + return 1; default: lprintf("%s: something unknown selected\n", __FUNCTION__); break; @@ -2240,7 +2239,7 @@ void menu_loop(void) do { me_loop_d(e_menu_main, &sel, NULL, draw_frame_main); - } while (!ready_to_go); + } while (!ready_to_go && !g_emu_want_quit); /* wait until menu, ok, back is released */ while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK)) diff --git a/frontend/plat_sdl.c b/frontend/plat_sdl.c index 5b853752..e3d70f60 100644 --- a/frontend/plat_sdl.c +++ b/frontend/plat_sdl.c @@ -72,6 +72,11 @@ static int change_video_mode(void) return plat_sdl_change_video_mode(w, h, 0); } +static void quit_cb(void) +{ + emu_core_ask_exit(); +} + void plat_init(void) { int ret; @@ -95,6 +100,7 @@ void plat_init(void) pl_rearmed_cbs.only_16bpp = 1; bgr_to_uyvy_init(); + plat_sdl_quit_cb = quit_cb; } void plat_finish(void) diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c index dfff8681..fff84010 100644 --- a/frontend/plugin_lib.c +++ b/frontend/plugin_lib.c @@ -606,7 +606,7 @@ void pl_frame_limit(void) struct timeval now; int diff, usadj; - if (g_resetting) + if (g_emu_resetting) return; vsync_cnt++;