Jump to content
  • Advertisement
Sign in to follow this  
Eric Muehlberg

Disappearing text in SDL

This topic is 2249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been creating a level editor for a 2D game using SDL in C++ and I have run into an interesting problem. I've gotten a working console implemented however after a couple minutes the text that is displayed in the console disappears, including the text I display showing the command currently being input. Does anyone have any idea as to why the text would spontaneously cease to be printed to the screen?

Code snippets:
http://pastebin.com/aiMwqSwf
http://pastebin.com/Xzs8gSbb

EDIT: narrowed the problem down to the console class acting up, not sure where to even begin looking for errors though.

Console class: //Excuse my terrible console
http://pastebin.com/sYUYEPRa
http://pastebin.com/hvcytUqc

Share this post


Link to post
Share on other sites
Advertisement
I think you may want contents.push_back(command); to not be executed if command contains an empty string, because I think this is causing the console text to be pushed off in some cases.

Share this post


Link to post
Share on other sites
I wish it were so simple. Console::Issue() is only ever called when the enter key is pressed. The weird part is that the text isn't being moved. One minute it is there, the next it simply vanishes as if the program was told to stop rendering it.

In displayConsole() (http://pastebin.com/aiMwqSwf) I commented out lines 12-20 and put another printS call that just prints a static phrase. When I do this the text stays on screen for as long as the console is open. I would think that if Issue() was being called I would watch my text scroll up the screen, but instead it vanishes as if contents itself is deleted. Edited by VisualDistortion

Share this post


Link to post
Share on other sites
Fair enough, but I think I'll need to look at more of your code to see what's causing the problem. On a related note, I am not sure how you managed to narrow the possibilities down to a problem in the Console class, seeing as any other part of the program can access the contents of the console.

Share this post


Link to post
Share on other sites
Well fortunately there aren't many places in which console is accessed. I narrowed it down to console simply because displayConsole() is the only thing called in the loop when there is no input from the user. The only thing called that modifies the console to be precise.

Aside the call of displayConsole(), this is the rest of the code that interacts with the console http://pastebin.com/RA8BGaBn

Share this post


Link to post
Share on other sites
SDL redirects streams from the console window to 'stdout.txt', I'm not sure if it copies the existing text too, though. In other words, if you find your missing text in that file then you just have to redirect the stream objects that you are using back to the console window.

Share this post


Link to post
Share on other sites

SDL redirects streams from the console window to 'stdout.txt', I'm not sure if it copies the existing text too, though. In other words, if you find your missing text in that file then you just have to redirect the stream objects that you are using back to the console window.


I don't work with the console. The console I work with is a drop down console of my own design. So nothing should ever reach the windows console.

Share this post


Link to post
Share on other sites
It is a vicious memory leak, try to free the previous SDL_Surface* of your text and recreate another one, because each update create à new surface without deleting the previous one so you've got no more memory.

Share this post


Link to post
Share on other sites

It is a vicious memory leak, try to free the previous SDL_Surface* of your text and recreate another one, because each update create à new surface without deleting the previous one so you've got no more memory.


I never thought a memory leak could cause an error such as this. I guess I always assumed that memory leaks would cause problems more along the line of increased memory usage or the program crashing, neither of which happened. Anyway thank you for your help.

And thanks to everyone who at the very least attempted to help, I appreciate it.

Share this post


Link to post
Share on other sites
That what I thought until I saw this problem on my game engine, if you're using C++ (and not C) I think you can catch the exception of the memory leak it could help you even you solved this case ^^

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!