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 - TTF_RenderUNICODE_Blended segmentation fault
Summary: TTF_RenderUNICODE_Blended segmentation fault
Status: RESOLVED INVALID
Alias: None
Product: SDL_ttf
Classification: Unclassified
Component: misc (show other bugs)
Version: 2.0.15
Hardware: x86_64 Windows 10
: P2 blocker
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-11 14:18 UTC by Davide Prade
Modified: 2019-06-12 07:33 UTC (History)
1 user (show)

See Also:


Attachments
Font used (837.25 KB, application/x-font-ttf)
2019-06-11 14:51 UTC, Davide Prade
Details

Note You need to log in before you can comment on or make changes to this bug.
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)