From 956c79e747a7ef40ddb13fa53a19a51160e08d83 Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Wed, 9 Apr 2014 07:51:06 +0000 Subject: [PATCH] Fixed freeing image surface and font at exit --- src/VirtualKeyboard.c | 14 ++++++++++++++ src/VirtualKeyboard.h | 1 + src/emulator.c | 5 +++++ src/menu_sdl.c | 18 ++++++++++++++++-- src/menu_sdl.h | 6 +++++- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/VirtualKeyboard.c b/src/VirtualKeyboard.c index 16bf256..8243d27 100644 --- a/src/VirtualKeyboard.c +++ b/src/VirtualKeyboard.c @@ -124,6 +124,20 @@ void VirtualKeyboard_init(SDL_Surface *screen) vkb_is_init = 1; } +void VirtualKeyboard_fini() +{ + if (vkb_is_init != 1) return; + + SDL_FreeSurface (image_kbd); + SDL_FreeSurface (image_sym); + SDL_FreeSurface (image_caps); + SDL_FreeSurface (image_kbd_small); + SDL_FreeSurface (image_sym_small); + SDL_FreeSurface (image_caps_small); + vkb_is_init = -1; + ordenador.vk_is_active=0; +} + void draw_vk() { diff --git a/src/VirtualKeyboard.h b/src/VirtualKeyboard.h index 3495713..a4caa00 100644 --- a/src/VirtualKeyboard.h +++ b/src/VirtualKeyboard.h @@ -45,6 +45,7 @@ typedef struct Virtual_Keyboard } VirtualKeyboard_struct; void VirtualKeyboard_init(SDL_Surface *screen); +void VirtualKeyboard_fini(void); struct virtkey* get_key(); struct virtkey* get_key_internal(); void draw_vk(); diff --git a/src/emulator.c b/src/emulator.c index 3d76334..07da5c3 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -39,6 +39,7 @@ #include "microdrive.h" #include "menu_sdl.h" #include "tape_browser.h" +#include "VirtualKeyboard.h" #include @@ -611,6 +612,9 @@ void end_system() { if(ordenador.tap_file!=NULL) fclose(ordenador.tap_file); + VirtualKeyboard_fini(); + menu_deinit(); + font_fini(); SDL_Quit(); if (!chdir(path_tmp)) {chdir("/"); remove_dir(path_tmp);} //remove the tmp directory if it exists @@ -1409,6 +1413,7 @@ int main(int argc,char *argv[]) font_init(); menu_init(ordenador.screen); + VirtualKeyboard_init(ordenador.screen); //Load the splash screen if (ordenador.zaurus_mini==0) if (load_zxspectrum_picture()) SDL_FreeSurface (image); diff --git a/src/menu_sdl.c b/src/menu_sdl.c index aab0d95..b1201f8 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -1465,14 +1465,28 @@ void font_init() free(font_path); } +void font_fini() +{ + TTF_CloseFont(menu_font16); + TTF_CloseFont(menu_font20); + TTF_CloseFont(menu_font8); + TTF_CloseFont(menu_font10); + + TTF_Quit(); +} + void menu_init(SDL_Surface *screen) { real_screen = screen; - - VirtualKeyboard_init(screen); is_inited = 1; } +void menu_deinit() +{ + real_screen = 0; + is_inited = 0; +} + int menu_is_inited(void) { return is_inited; diff --git a/src/menu_sdl.h b/src/menu_sdl.h index 326110c..32970f0 100644 --- a/src/menu_sdl.h +++ b/src/menu_sdl.h @@ -62,10 +62,14 @@ int msgInfo(char *text, int duration, SDL_Rect *rc); int msgYesNo(char *text, int def,int x, int y); -void font_init(); +void font_init(void); + +void font_fini(void); void menu_init(SDL_Surface *screen); +void menu_deinit(void); + int menu_is_inited(void); int ext_matches(const char *name, const char *ext);