Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:27:00+00:00 2026-06-07T04:27:00+00:00

In my game, when the time is active, it would always crash after 5

  • 0

In my game, when the “time” is active, it would always crash after 5 “hours”. When it’s running, it’s working fine until it starts displaying an incorrect time (for reasons unknown) and it would crash after 5 “hours” due to a segmentation fault. That’s weird because there’s no such thing before and it’s supposed to be doing the same thing over and over. This is my code. Try to tell me if there’s a place where a memory leak could occur over time. BTW, the “time_tick()” occurs every “while” loop.

struct global_struct
{
    int seconds;
    int minutes;
    int hours;
    TTF_Font * font;
    SDL_Color font_color;
    SDL_Color bk_color;
};
global_struct global;

void GL_RENDER_TTF(const char * Text, TTF_Font * Font, SDL_Color Textcolor, SDL_Color bk_color, int x, int y, float depth)
{
SDL_Surface * surface;
int w;
int h;

if(!(Font == NULL))
{
    surface = TTF_RenderUTF8_Shaded(Font,Text,Textcolor,bk_color);
    if(!(surface == NULL))
    {
        w = surface->w;
        h = surface->h;
        GLuint texture;
        GLenum texture_format;
        GLint nOfColors;
        surface = SDL_DisplayFormatAlpha(surface);

        nOfColors = surface->format->BytesPerPixel;
        if (nOfColors == 4)
        {
            if (surface->format->Rmask == 0x000000ff)
                texture_format = GL_RGBA;
            else
                texture_format = GL_BGRA;
        }
        else if (nOfColors == 3)
        {
            if (surface->format->Rmask == 0x000000ff)
                texture_format = GL_RGB;
            else
                texture_format = GL_BGR;
        }

        glGenTextures( 1, &texture );

        glBindTexture( GL_TEXTURE_2D, texture );

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

        glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels );

        glBindTexture(GL_TEXTURE_2D, texture);

        glBegin(GL_QUADS);

            glTexCoord2f(0.0f,0.0f); glVertex3f(x,y,depth);
            glTexCoord2f(1.0f,0.0f); glVertex3f(x+w,y,depth);
            glTexCoord2f(1.0f,1.0f); glVertex3f(x+w,y+h,depth);
            glTexCoord2f(0.0f,1.0f); glVertex3f(x,y+h,depth);

        glEnd();
    };
};
};

void time_tick(float depth1)
{
global.seconds = global.seconds + 1;
if(global.seconds > 59)
{
    global.seconds = 0;
    global.minutes = global.minutes + 1;
};
if(global.minutes > 59)
{
    global.minutes = 0;
    global.hours = global.hours + 1;
};
if(global.hours > 23)
{
    global.hours = 0;
};
string time;
string shours;
string sminutes;
string sseconds;
stringstream ssseconds;
stringstream ssminutes;
stringstream sshours;
ssseconds << global.seconds;
ssminutes << global.minutes;
sshours << global.hours;
if(global.hours < 10)
{
    shours = "0"+sshours.str();
}
else
{
    shours = sshours.str();
};
if(global.minutes < 10)
{
    sminutes = "0"+ssminutes.str();
}
else
{
    sminutes = ssminutes.str();
};
if(global.seconds < 10)
{
    sseconds = "0"+ssseconds.str();
}
else
{
    sseconds = ssseconds.str();
};
time = "time: "+shours+"h "+sminutes+"m "+sseconds+"s";
GL_RENDER_TTF(time.c_str(),global.font,global.font_color,global.bk_color,0,0,depth1);
SDL_Delay(10);
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:27:02+00:00Added an answer on June 7, 2026 at 4:27 am

    Everytime you call RENDER_TTF you’re creating a new texture, whilst the texture from the previous one still lingers around. If you can use a constant texture size, use glTexSubImage2D to replace the texture contents. Otherwise use glDeleteTextures to free the only texture, before creating a new one.

    You can also reuse a texture ID by just calling glTexImage2D anew with the old texture object being bound (i.e. no glGenTextures, but this is discouraged by recent versions of OpenGL and glTexStorage completely disallows it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been thinking for a long time about working on a multiplayer game in
I'm working on a real-time game application. Most of it is written in Java,
I'm currently in the planning stages for a real-time multiplayer game that would be
Is there a straight forward way to keep track of game time in Android
I'm building a real time game, mostly chat based, and I need to have
I'm developing a real time strategy game clone on the Java platform and I
I have a spot a difference game that every time I solve an image,
I am using Java to create a graphical game and every time I wish
For some time I've been making a 2d tile based sim game, and it's
I'm trying to make a multiplayer game for the first time on Android. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.