From 9f9e35689e7536b3449c55a34b121ecc18c28c6f Mon Sep 17 00:00:00 2001 From: kreatordxx <> Date: Sun, 25 Jul 2010 02:30:53 +0000 Subject: [PATCH] For menus, only call the user function for closing immediately before closing, fixing memory errors when the user function frees memory --- CHANGELOG.txt | 1 + main/newmenu.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d4648fdb3..bdce7cccb 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ D1X-Rebirth Changelog -------- arch/sdl/event.c, arch/ogl/gr.c, arch/sdl/gr.c: Exit SDL_PollEvent early if window changes, to avoid menu problems when pressing keys fast; fix 'condition is always false' warning main/inferno.c, main/inferno.h: Rewrite quit system, fixing *many* bugs with it :P +main/newmenu: For menus, only call the user function for closing immediately before closing, fixing memory errors when the user function frees memory 20100721 -------- diff --git a/main/newmenu.c b/main/newmenu.c index 9311cd758..009b226f4 100644 --- a/main/newmenu.c +++ b/main/newmenu.c @@ -1475,7 +1475,7 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu) if (event->type == EVENT_WINDOW_CLOSED) return 0; - if (menu->subfunction) + if (menu->subfunction && (event->type != EVENT_WINDOW_CLOSE)) { int rval = (*menu->subfunction)(menu, event, menu->userdata); if (rval) @@ -1533,7 +1533,10 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu) } if (window_exists(wind)) + { + (*menu->subfunction)(menu, event, menu->userdata); // can't cancel here - too hard d_free(menu); + } break; default: