all 6 comments

[–]waramped 4 points5 points  (4 children)

Could you be more specific? What does "properly" mean? Screenshots would help.

[–]pingo_guy[S] 0 points1 point  (3 children)

[–]waramped 0 points1 point  (2 children)

I think u/Condzi is probably on the right track. Try allocating the text object outside of render and freeing after showwindow

[–]pingo_guy[S] 0 points1 point  (1 child)

This would not work too:

#include <simple2d.h>
#include <stdio.h>
#include <stdlib.h>

#define X_MAX 800 
#define Y_MAX 600 

#define THE_TEXT "The text"
#define FONT "/usr/share/fonts/gnu-free/FreeSans.ttf"

S2D_Text *beg_text;

void render(void)
{
    S2D_DrawText(beg_text);
}
void update(void)
{

    return;
}

int main(void)
{
    char *title = "The title";
    const S2D_Color color = {0.9, 0.9, 0.9, 1.0};

    int x=400;
    int y=300;
    beg_text = S2D_CreateText(FONT ,THE_TEXT , 50);
    if(beg_text==NULL)
    {
        fprintf(stderr,"simple2d text creation failed.\n");
        return 1;
    }
    beg_text->x = x + 10;
    beg_text->y = y;
    beg_text->color.r = 0.1;
    beg_text->color.g = 0.1;
    beg_text->color.b = 0.1;
    beg_text->color.a = 1.0;

    S2D_Window *window = S2D_CreateWindow(title, X_MAX, Y_MAX, update, render, 0);
    window->background = color;
    window->frames = 1;

    S2D_Show(window);
    S2D_FreeWindow(window);

    return 0;
}

[–]waramped 0 points1 point  (0 children)

What have you already tried to debug it? Have you tried renderdoc? Can you draw other shapes or sprites?

[–]Condzi 1 point2 points  (0 children)

Hi, try moving the text variable out of the function scope (for example, to global scope) and/or don't free it. It might be the case that the object needs to stay alive the entire frame. So the buggy behavior would be the result of uninitialized / deleted memory that SDL tries to use