Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on a game in C++ and SDL2(as well as SDL_image and SDL_ttf) and when I try to render text, it freezes and stops responding. I believe it happens when I call TTF_RenderText_Solid:
C++
void Text::Render(const char* text, SDL_Color color) {
	SDL_Surface* surf = new SDL_Surface;
	surf = TTF_RenderText_Solid(font_, text, color);
	texture_ = SDL_CreateTextureFromSurface(renderer_, surf);
	SDL_QueryTexture(texture_, NULL, NULL, &rect_.w, &rect_.h);
	SDL_FreeSurface(surf);
	delete surf;
}


What I have tried:

I have tried debugging and inserting breakpoints to track down what's going wrong. I haven't figured out why it isn't working yet, so I am unable to try any real solution. I haven't found any instances where someone else ran into this issue.
Posted
Updated 14-Nov-22 15:24pm

1 solution

I was looking through the sample code at C++ TTF_RenderText_Solid Examples - HotExamples[^] and none of them create a SDL_Surface object. They use the pointer returned from TTF_RenderText_Solid. You might want to start by removing that object creation call.

Beyond that, I would probably resort to printf-style debugging using the tracing mechanism of your choice.
 
Share this answer
 
Comments
Skuttle Team 14-Nov-22 22:11pm    
Thanks for the help! The program now seems to crash with this error(i'm using Visual Studio):
Exception thrown at 0x00007FFDC28ABF05 (SDL2_ttf.dll) in PROGRAM.exe: 0xC0000005: Access violation reading location 0x0000000000000188.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900