Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Disappearing text in SDL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 VisualDistortion   Members   -  Reputation: 112

Like
0Likes
Like

Posted 19 July 2012 - 07:05 PM

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

Ad:

#2 RulerOfNothing   Members   -  Reputation: 808

Like
0Likes
Like

Posted 19 July 2012 - 10:58 PM

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.

#3 VisualDistortion   Members   -  Reputation: 112

Like
0Likes
Like

Posted 20 July 2012 - 02:32 AM

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, 20 July 2012 - 02:34 AM.


#4 RulerOfNothing   Members   -  Reputation: 808

Like
0Likes
Like

Posted 20 July 2012 - 02:54 AM

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.

#5 VisualDistortion   Members   -  Reputation: 112

Like
0Likes
Like

Posted 20 July 2012 - 11:24 AM

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

#6 The Magical Pot   Members   -  Reputation: 149

Like
0Likes
Like

Posted 20 July 2012 - 03:46 PM

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.

#7 VisualDistortion   Members   -  Reputation: 112

Like
0Likes
Like

Posted 20 July 2012 - 05:07 PM

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.

#8 Bartpab   Members   -  Reputation: 109

Like
1Likes
Like

Posted 23 July 2012 - 09:17 PM

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.

#9 VisualDistortion   Members   -  Reputation: 112

Like
0Likes
Like

Posted 24 July 2012 - 12:43 AM

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.

#10 Bartpab   Members   -  Reputation: 109

Like
0Likes
Like

Posted 24 July 2012 - 05:02 AM

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 ^^




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS