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 4083

Summary: Application crashes
Product: SDL_ttf Reporter: Lísias de Castro <saisilcastro>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.14   
Hardware: x86_64   
OS: Windows 10   

Description Lísias de Castro 2018-02-15 20:34:27 UTC
When I run my application and put some text on the main loop,
with the time it crashes. It only occurs when I use the print function.
I loaded more than 100 sprites, and leave the application running all the
night and it did not crash. But as soon as I use the print function
it crashes the application.
Here is my code.

PLACE_CALL STATUS PLACE_TYPE place_print(struct PlaceTag * to, struct ObjectTag * object, struct FontTag * font, struct ColorTag * color, B8 * format, ...) {
    if (to && to->machine && to->machine->sdl2 && to->machine->sdl2->pallet &&
            object && font && font->ttf && color) {
        char * str = NULL;
        int len = 0;
        va_list list;
        va_start(list, format);
        len = _vscprintf(format, list);
        str = (char *) calloc(len + 1, sizeof (char));
        if (str)vsprintf(str, format, list);
        va_end(list);
        SDL_Color fg = {color->r, color->g, color->b, color->a};
        object->image->memory = (str) ? image_text_set(str, to->machine->sdl2->pallet, font->ttf, fg) : NULL;
        if (str)free(str);
        return (On);
    }
    return (Off);
}

SDL2_PLUGIN_CALL SDL_Texture * SDL2_PLUGIN_TYPE image_text_set(const B8 * text, SDL_Renderer * renderer, TTF_Font * font, SDL_Color text_color) {
    SDL_Surface * solid = TTF_RenderUTF8_Solid(font, text, text_color);
    if (solid) {
        SDL_Texture * to = SDL_CreateTextureFromSurface(renderer, solid);
        SDL_FreeSurface(solid);
        return (to);
    }
    return (NULL);
}
Comment 1 Lísias de Castro 2018-02-22 01:07:06 UTC
I discovered what was happening.
I forgot to destroy the surface and texture before
to make a new print. So the computer had memory leak.
Now I am debbuging it for more than 5 hours and the application
keeps running smoothly.
Comment 2 Sam Lantinga 2018-02-22 01:28:35 UTC
I'm glad you figured it out!
Comment 3 Lísias de Castro 2018-02-22 01:39:40 UTC
And I am glad you do care.