SDL_ttf: Segfault on Windows 2.0.18 release for certain fonts/sizes
Over at pygame we got an issue report after updating to SDL_ttf 2.0.18 that rendering a font that previously worked segfaulted their program. It only seems to segfault at certain sizes.
I wanted to be sure this was a problem at the C level, and not an unrelated regression by pygame, so I put together a small test script.
#include "SDL.h"
#include "SDL_ttf.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
SDL_SetMainReady();
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = NULL;
SDL_Surface *screen = NULL;
window = SDL_CreateWindow("Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 150, SDL_WINDOW_SHOWN);
screen = SDL_GetWindowSurface(window);
SDL_FillRect(screen, NULL, SDL_MapRGBA(screen->format, 0, 0, 120, 255));
printf("running on patch level %i\n", SDL_TTF_PATCHLEVEL);
TTF_Init();
// font size 70 = segfault, 20 = fine
TTF_Font* f = TTF_OpenFont("PlayfairDisplay-Regular.ttf", 20);
printf("error=%s\n", SDL_GetError());
SDL_Color white;
white.r = 255;
white.g = 255;
white.b = 255;
white.a = 255;
//SDL_Surface *text = TTF_RenderText_Blended(f, "Hello world", white);
SDL_Surface *text = TTF_RenderUTF8_Blended(f, "Hello world", white);
printf("text=%p\n", text);
printf("error=%s\n", SDL_GetError());
SDL_BlitSurface(text, NULL, screen, NULL);
printf("error=%s\n", SDL_GetError());
SDL_UpdateWindowSurface(window);
printf("error=%s\n", SDL_GetError());
// Keep the main loop until the window is closed (SDL_QUIT event)
int exit = 0;
SDL_Event eventData;
while (!exit)
{
while (SDL_PollEvent(&eventData))
{
switch (eventData.type)
{
case SDL_QUIT:
exit = 1;
break;
}
}
}
SDL_Quit();
return 0;
}
Both pygame and my test script are compiled with Visual Studio, and use the 64 bit dev VS SDL_ttf 2.0.18 release. I tried to replicate this bug on my Mac, but I was unable to.
Running this in the VS debugger yields:
Unhandled exception at 0x00007FFDE6C723F6 (ntdll.dll) in SDL_c_test.exe: 0xC0000028: An invalid or unaligned stack was encountered during an unwind operation.
^ This pops up over the call to TTF_RenderUTF8_Blended
Call stack:
This hits the playfair family, at least regular and semibold (those are the ones I tested). PlayfairDisplay-Regular.zip
I also tested this through pygame with all the system fonts pygame could detect, and got failures on the fonts
algerian, castellar, gigi, imprintshadow, blackadderitc, edwardianscriptitc, kunstlerscript
maturascriptcapitals, oldenglishtext, msoutlook, parchment, vivaldi, vladimirscript
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 23 (13 by maintainers)
I’ll leave this issue open for verification with the final 2.20.0 release candidate build.
Thanks!
The good news is, I can reproduce this, so I can see if the workaround is viable.