Skip to content

TTF_GetGPUTextDrawData "crash" #619

Description

@gibki

Requesting draw data for the text of " " (single space) shuts down the program on the spot with no additional output.

#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3_ttf/SDL_ttf.h>

int main(int argc, char *argv[]){
    SDL_SetLogPriorities(SDL_LOG_PRIORITY_DEBUG);
    SDL_Init(SDL_INIT_VIDEO);

    SDL_Window *window = SDL_CreateWindow("TTF", 800, 800, 0);
    SDL_GPUDevice *device = SDL_CreateGPUDevice(SDL_GPU_SHADERFORMAT_SPIRV, true, "vulkan");
    SDL_ClaimWindowForGPUDevice(device, window);

    if (!TTF_Init()){
        SDL_LogDebug(0, SDL_GetError());
        return SDL_APP_FAILURE;
    }
    SDL_LogDebug(0, "SDL_ttf version: %d", TTF_Version());
    TTF_TextEngine *text_engine = TTF_CreateGPUTextEngine(device);
    if (text_engine == NULL){
        SDL_LogDebug(0, SDL_GetError());
        return SDL_APP_FAILURE;
    }

    TTF_Font *font = TTF_OpenFont("./arial.ttf", 12);
    if (font == NULL){
        SDL_LogDebug(0, SDL_GetError());
        return SDL_APP_FAILURE;
    }

    SDL_LogDebug(0, "Create text");
    TTF_Text *text = TTF_CreateText(text_engine, font, " ", 1);
    if (text == NULL){
        SDL_LogDebug(0, SDL_GetError());
        return SDL_APP_FAILURE;
    }
    SDL_LogDebug(0, "Get text draw data");
    TTF_GPUAtlasDrawSequence *atlas_sequence = TTF_GetGPUTextDrawData(text);  // <<<---
    if (atlas_sequence == NULL){  // never reached
        SDL_LogDebug(0, SDL_GetError());
        return SDL_APP_FAILURE;
    }

    SDL_LogDebug(0, "Event loop");
    SDL_Event event;
    bool quit_event = false;
    while(!quit_event){
        while (SDL_PollEvent(&event)){
            if (event.type == SDL_EVENT_QUIT){
                quit_event = true;
            }
        }
    }

    TTF_DestroyText(text);
    TTF_CloseFont(font);
    TTF_DestroyGPUTextEngine(text_engine);
    TTF_Quit();

    SDL_ReleaseWindowFromGPUDevice(device, window);
    SDL_DestroyGPUDevice(device);
    SDL_Quit();
    return SDL_APP_SUCCESS;
}

Happens on multiple versions, also on latest, SDL revision: SDL-3.5.0-release-3.4.0-454-gad9138470 SDL_ttf version: 3003000

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions