| Summary: | TTF_RenderUNICODE_Blended segmentation fault | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Davide Prade <davide.prade> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | blocker | ||
| Priority: | P2 | CC: | sylvain.becker |
| Version: | 2.0.9 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 10 | ||
| Attachments: | Font used | ||
you would need to check with latest SDL2_ttf code because it has changed I am using the last available on MSYS2.
$ pacman -Ss SDL2_ttf
mingw64/mingw-w64-x86_64-SDL2_ttf 2.0.15-1 [installed]
A library that allows you to use TrueType fonts in your SDL applications (Version 2) (mingw-w64)
Commenting on calls to "SDL_FreeSurface" works.
This isn't the latest head source. Can you attach your font so that I can try ? Created attachment 3816 [details]
Font used
It doesn't crash with latest, but I guess you need to null-terminated your strings The crash happens also with null terminated strings and also with other fonts.
const Uint16 txt1[] = {'P', 'u', 's', 'h', ' ', 'U', 'p', ' ', '1', '\0'};
const Uint16 txt2[] = {'P', 'u', 's', 'h', ' ', 'U', 'p', ' ', '2', '\0'};
I am a little bit sceptical. The test-case was clearly broken. Did you recompile it ? I suggest you try with the latest SDL_ttf source, from mercurial. (you'll need probably also head SDL sources). I have created a minimal project and it works. Probably there are some kind of issues with linked libraries in the original project. Do you have any idea how to find the problem with the linked libraries? Ok, thant for the feedback, so I close both tickets. (bug 4664 and bug 4663) You can use valgrind to catch issues ! make sure to clean all project and recompile Marked as resolved I reopen the issue because I isolate the problem around "SDL_PixelFormat", more precisely in the "SDL_FreeFormat" function that doesn't set "formats" pointer (SDL_pixels.c) to NULL, but I don't know why.
If I redefine "TTF_Render*_Blended" functions the problem is resolved.
---------------------------
inline SDL_Surface *TTF_RenderText_Blended_WRAPPER(TTF_Font *font, const char *text, SDL_Color fg) {
SDL_Surface *surf = TTF_RenderText_Blended(font, text, fg);
if (surf->format->refcount == 1) {
surf->format->refcount++;
}
return surf;
}
inline SDL_Surface *TTF_RenderUTF8_Blended_WRAPPER(TTF_Font *font, const char *text, SDL_Color fg) {
SDL_Surface *surf = TTF_RenderUTF8_Blended(font, text, fg);
if (surf->form at->refcount == 1) {
surf->format->refcount++;
}
return surf;
}
inline SDL_Surface *TTF_RenderUNICODE_Blended_WRAPPER(TTF_Font *font, const Uint16 *text, SDL_Color fg) {
SDL_Surface *surf = TTF_RenderUNICODE_Blended(font, text, fg);
if (surf->format->refcount == 1) {
surf->format->refcount++;
}
return surf;
}
#define TTF_RenderText_Blended TTF_RenderText_Blended_WRAPPER
#define TTF_RenderUTF8_Blended TTF_RenderUTF8_Blended_WRAPPER
#define TTF_RenderUNICODE_Blended TTF_RenderUNICODE_Blended_WRAPPER
---------------------------
I don't understand why the GDB debugger doesn't go into the "SDL_FreeFormat" function, and seems that manual modification in the same function is completely ignored. Changes to the other functions are taken into account instead (for example "SDL_AllocFormat").
I resolved the issue: it was just a difficult to find linker problem (a CMake WIN32/MINGW IF statement in a dynamic sub-library). |
The following code generates a segmentation fault on the marked line. I compile on MSYS2 MinGW 64 bit: - mingw64/mingw-w64-x86_64-SDL2 2.0.9-1 - mingw64/mingw-w64-x86_64-SDL2_ttf --------------------------- Thread 1 received signal SIGSEGV, Segmentation fault. 0x000000006c7c6100 in ?? () from SDL2.dll (gdb) bt #0 0x000000006c7c6100 in ?? () from SDL2.dll #1 0x000000006c7c9d03 in ?? () from SDL2.dll #2 0x0000000071003922 in ?? () from SDL2_ttf.dll #3 0x0000000071003e24 in ?? () from SDL2_ttf.dll #4 0x0000000000450e61 in main (argc=1, argv=0x5c74390) at test.cpp:100 --------------------------- --------------------------- if (TTF_Init() != 0) { fprintf(stderr, "Couldn't initialize TTF library"); } else { TTF_Font *font = TTF_OpenFont("arialbd.ttf", 26); if (font != NULL) { SDL_Color col = {255, 255, 255, 255}; const Uint16 txt1[] = {'P', 'u', 's', 'h', ' ', 'U', 'p', ' ', '1'}; SDL_Surface *surf1 = TTF_RenderUNICODE_Blended(font, txt1, col); SDL_FreeSurface(surf1); surf1 = NULL; const Uint16 txt2[] = {'P', 'u', 's', 'h', ' ', 'U', 'p', ' ', '2'}; /*SEGFAULT*/SDL_Surface *surf2 = TTF_RenderUNICODE_Blended(font, txt2, col); SDL_FreeSurface(surf2); surf2 = NULL; TTF_CloseFont(font); font = NULL; } else { fprintf(stderr, "Couldn't open font"); } } ---------------------------