commit 8edf2da
neauoire
·
2023-08-16 20:37:17 +0000 UTC
parent c09a047
Destroy assets on emu_end
1 files changed,
+15,
-14
+15,
-14
1@@ -90,6 +90,17 @@ emu_restart(Uxn *u, char *rom, int soft)
2 /* set window title */
3 }
4
5+static int
6+emu_end(Uxn *u)
7+{
8+ free(u->ram);
9+ XDestroyImage(ximage);
10+ XDestroyWindow(display, window);
11+ XCloseDisplay(display);
12+ exit(0);
13+ return u->dev[0x0f] & 0x7f;
14+}
15+
16 static void
17 hide_cursor(void)
18 {
19@@ -131,10 +142,7 @@ emu_event(Uxn *u)
20 XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, uxn_screen.width, uxn_screen.height);
21 break;
22 case ClientMessage: {
23- XDestroyImage(ximage);
24- XDestroyWindow(display, window);
25- XCloseDisplay(display);
26- exit(0);
27+ emu_end(u);
28 } break;
29 case KeyPress: {
30 KeySym sym;
31@@ -180,6 +188,9 @@ emu_event(Uxn *u)
32 static int
33 emu_init(void)
34 {
35+ display = XOpenDisplay(NULL);
36+ if(!display)
37+ return system_error("X11", "Could not open display");
38 screen_resize(WIDTH, HEIGHT);
39 return 1;
40 }
41@@ -196,7 +207,6 @@ emu_run(Uxn *u, char *rom)
42 /* display */
43 Atom wmDelete;
44 static Visual *visual;
45- display = XOpenDisplay(NULL);
46 visual = DefaultVisual(display, 0);
47 window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width * SCALE + PAD * 2, uxn_screen.height * SCALE + PAD * 2, 1, 0, 0);
48 if(visual->class != TrueColor)
49@@ -240,15 +250,6 @@ emu_run(Uxn *u, char *rom)
50 return 1;
51 }
52
53-static int
54-emu_end(Uxn *u)
55-{
56- XDestroyImage(ximage);
57- close(0);
58- free(u->ram);
59- return u->dev[0x0f] & 0x7f;
60-}
61-
62 int
63 main(int argc, char **argv)
64 {