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

  • SEARCH
  • Home
  • 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 8172165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:41:53+00:00 2026-06-06T21:41:53+00:00

I’m making a Yahtzee-like (a dice game with scoring) in c++ using SDL. It’s

  • 0

I’m making a Yahtzee-like (a dice game with scoring) in c++ using SDL. It’s my first SDL project to develop on my own.

The problem can be described as: When I start the game, text is rendering fine. I can place scores and continue the game. However, if I wait for a few minutes (whether I’m still playing or not), the text eventually ceases to render. I can continue the game, but no text will display, and the previously displayed text is no longer displayed.

I’m completely baffled by this issue. It has not happened until now, as none of the games before now were long enough for me to notice.

Note: one thing that I stumbled upon was software and hardware rendering. I’m not sure why, but I tried to render with the hardware instead, and that did not solve the problem.

Another note: The text rendering part of the code is towards the end, in a for-loop.

I’m lost, can anyone help me? I’ll post the code, but it’s long, ridiculous, and I don’t think it is the issue.

int GUI(State& GameState)
{       
apply_surface( 0, 0, background, screen ); //background
apply_surface( SCORE_X, SCORE_Y, scoreImage, screen ); //score card
apply_surface( KEPT_TRAY_X, KEPT_TRAY_Y, keptTray, screen ); //kept tray
apply_surface( TEXT_BOX_X, TEXT_BOX_Y, textBox, screen ); //text box

//Blatantly handles only the next event on the queue per frame
if( SDL_PollEvent( &event ) )
    eventHandler(GameState);

//place button
if(GameState.placeButtonClicked)
{
    apply_surface( GameState.buttonV[GameState.placeButtonClicked].x, GameState.buttonV[GameState.placeButtonClicked].y, clickedButton, screen );
}

//dice[1]
apply_surface( *GameState.diceV[1].pointX, *GameState.diceV[1].pointY, *GameState.diceV[1].surfaceValue, screen );

//dice[2]
apply_surface( *GameState.diceV[2].pointX, *GameState.diceV[2].pointY, *GameState.diceV[2].surfaceValue, screen );

//dice[3]
apply_surface( *GameState.diceV[3].pointX, *GameState.diceV[3].pointY, *GameState.diceV[3].surfaceValue, screen );

//dice[4]
apply_surface( *GameState.diceV[4].pointX, *GameState.diceV[4].pointY, *GameState.diceV[4].surfaceValue, screen );

//dice[5]
apply_surface( *GameState.diceV[5].pointX, *GameState.diceV[5].pointY, *GameState.diceV[5].surfaceValue, screen );

//rollButton
if(GameState.navV[1].clicked)
{
    apply_surface( GameState.navV[1].x, GameState.navV[1].y, rollButtonClicked, screen);
}
else
{
    apply_surface( GameState.navV[1].x, GameState.navV[1].y, rollButton, screen );
}

//endTurnButton
if(GameState.navV[2].clicked)
{
    apply_surface( GameState.navV[2].x, GameState.navV[2].y, endTurnButtonClicked, screen );
}
else
{
    apply_surface( GameState.navV[2].x, GameState.navV[2].y, endTurnButton, screen );
}

//displaying the clickedButton if a score is clicked
if(GameState.placeButtonClicked != 0)
{
    apply_surface( GameState.buttonV[GameState.placeButtonClicked].x, GameState.buttonV[GameState.placeButtonClicked].y, clickedButton, screen );
}

//displaying the scores for each "button" (each score segment)
for(int i = 1; i <= (GameState.buttonV.size() - 1); i++)
{
    if(GameState.buttonV[i].value >= 0)
    {
        message = TTF_RenderText_Solid( scoreFont, GameState.buttonV[i].valueString, scoreFontColor );
        apply_surface( GameState.buttonV[i].x + 10, GameState.buttonV[i].y + 2, message, screen );
    }
}

if( SDL_Flip( screen ) == -1 )
{
    return 1;
}

decGUICounters(GameState);

return 0;

}

  • 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-06T21:41:55+00:00Added an answer on June 6, 2026 at 9:41 pm

    I found the answer browsing this website (it took a while!). Hopefully I can help someone else out with what I found:

    The problem was that I was repeatedly setting new text to message:

    message = TTF_RenderText_Solid(etc);
    

    When you call TTF_RenderText_Solid(), it returns a new surface to the surface pointer (message). However, it does not free the RAM that the old surface contained.

    All you have to do is: SDL_FreeSurface(message); before you assign new memory to the surface pointer (message).

    This prevents a memory leak, which in turn prevents your memory from randomly being obliterated by the CPU.

    TL;DR:
    
    SDL_FreeSurface(message);
    

    Before:

    message = TTF_RenderText_Solid();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

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.