From 8edf2da7c84ee28094ef70170eccc687b888f6fd Mon Sep 17 00:00:00 2001 From: neauoire Date: Wed, 16 Aug 2023 13:37:17 -0700 Subject: [PATCH] Destroy assets on emu_end --- src/uxn11.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/uxn11.c b/src/uxn11.c index 7a1ea5a..21e8b1e 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -90,6 +90,17 @@ emu_restart(Uxn *u, char *rom, int soft) /* set window title */ } +static int +emu_end(Uxn *u) +{ + free(u->ram); + XDestroyImage(ximage); + XDestroyWindow(display, window); + XCloseDisplay(display); + exit(0); + return u->dev[0x0f] & 0x7f; +} + static void hide_cursor(void) { @@ -131,10 +142,7 @@ emu_event(Uxn *u) XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, uxn_screen.width, uxn_screen.height); break; case ClientMessage: { - XDestroyImage(ximage); - XDestroyWindow(display, window); - XCloseDisplay(display); - exit(0); + emu_end(u); } break; case KeyPress: { KeySym sym; @@ -180,6 +188,9 @@ emu_event(Uxn *u) static int emu_init(void) { + display = XOpenDisplay(NULL); + if(!display) + return system_error("X11", "Could not open display"); screen_resize(WIDTH, HEIGHT); return 1; } @@ -196,7 +207,6 @@ emu_run(Uxn *u, char *rom) /* display */ Atom wmDelete; static Visual *visual; - display = XOpenDisplay(NULL); visual = DefaultVisual(display, 0); window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width * SCALE + PAD * 2, uxn_screen.height * SCALE + PAD * 2, 1, 0, 0); if(visual->class != TrueColor) @@ -240,15 +250,6 @@ emu_run(Uxn *u, char *rom) return 1; } -static int -emu_end(Uxn *u) -{ - XDestroyImage(ximage); - close(0); - free(u->ram); - return u->dev[0x0f] & 0x7f; -} - int main(int argc, char **argv) {