We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4663

Summary: TTF_RenderUNICODE_Blended segmentation fault
Product: SDL_ttf Reporter: Davide Prade <davide.prade>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: blocker    
Priority: P2 CC: sylvain.becker
Version: 2.0.15   
Hardware: x86_64   
OS: Windows 10   
Attachments: Font used

Description Davide Prade 2019-06-11 14:18:38 UTC
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 D:\Repositories\Git\solari-gt3\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");
        }
    }
---------------------------
Comment 1 Sylvain 2019-06-11 14:24:39 UTC
you would need to check with latest SDL2_ttf code because it has changed
Comment 2 Davide Prade 2019-06-11 14:29:09 UTC
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.
Comment 3 Davide Prade 2019-06-11 14:51:50 UTC
Created attachment 3817 [details]
Font used
Comment 4 Davide Prade 2019-06-11 15:06:57 UTC
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'};
Comment 5 Sylvain 2019-06-12 07:33:51 UTC
Ok, thanks for the feedback, so I close both tickets. (bug 4664 and bug 4663)