From 74c460d3f2b51ecd79a797ee7e8b4c6b56fc7427 Mon Sep 17 00:00:00 2001 From: John Popplewell Date: Fri, 17 Dec 2010 15:43:53 +0000 Subject: [PATCH] Cleaned up a couple of problems when DEBUG is defined. Enabled fmemopen_alternative on Windows. Rearranged calls to rsvg_init()/rsvg_term() so that they are only called once at startup and shutdown. This was causing segfaults when opening SVG files and apparently it's not just Tux Paint: http://0pointer.de/blog/projects/beware-of-rsvg-term.html Slightly hysterical, but a quick Google search reveals other projects with the same problem/solution. Builds and runs on Windows again. --- src/tuxpaint.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/tuxpaint.c b/src/tuxpaint.c index cdf726737..9a7492eca 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -501,7 +501,7 @@ extern WrapperData macosx; //#define fmemopen_alternative */ /* Uncomment this to test the fmemopen alternative in systems were fmemopen exists */ -#if defined (__HAIKU__) // Haiku needs it, at least for now +#if defined (__HAIKU__) || defined (WIN32) // Haiku and MINGW/MSYS need it, at least for now #define fmemopen_alternative #endif @@ -12404,7 +12404,13 @@ static void cleanup(void) TTF_Quit(); SDL_Quit(); - + /* Call this once only, at exit */ +#if !defined(NOSVG) && !defined(OLD_SVG) +#ifdef DEBUG + printf("rsvg_term()\n"); fflush(stdout); +#endif + rsvg_term(); +#endif } @@ -16535,7 +16541,7 @@ static int charsize(Uint16 c) str[0] = c; str[1] = '\0'; - TTF_SizeUNICODE(getfonthandle(cur_font), str, &w, &h); + TTF_SizeUNICODE(getfonthandle(cur_font)->ttf_font, str, &w, &h); return w; } @@ -17071,8 +17077,6 @@ static SDL_Surface * load_svg(char * file) /* Create an RSVG Handle from the SVG file: */ - rsvg_init(); - gerr = NULL; rsvg_handle = rsvg_handle_new_from_file(file, &gerr); @@ -17221,8 +17225,6 @@ static SDL_Surface * load_svg(char * file) free(image); cairo_destroy(cr); - rsvg_term(); - return(sdl_surface); } @@ -22545,6 +22547,14 @@ static void setup(void) signal(SIGPIPE, signal_handler); #endif + + /* Call this once */ +#if !defined(NOSVG) && !defined(OLD_SVG) +#ifdef DEBUG + printf("rsvg_init()\n"); fflush(stdout); +#endif + rsvg_init(); +#endif } @@ -23591,10 +23601,6 @@ int button(int id, int x, int y) if (texttool_len < (sizeof(texttool_str) / sizeof(wchar_t)) - 1) { int old_cursor_textwidth = cursor_textwidth; -#ifdef DEBUG - wprintf(L" key = <%c>\nunicode = <%lc> 0x%04x %d\n\n", - key_down, key_unicode, key_unicode, key_unicode); -#endif texttool_str[texttool_len++] = *im_cp; texttool_str[texttool_len] = 0;