SDL Not Working

closed account (N36fSL3A)
Okay, so I've been working on this simple platformer in my spare time, now it came to a movement test. Well, when I try to run it, it freezes. So naturally, I try to close the window, but then, it displays a message "<Insert .exe here> Stopped working and it closed down. I linked libraries correctly, and It was working with displaying a few images on the screen earlier in my loop. Now that I have a player added to everything, it screws up. Please help me, I hope this is enough. Tell me if you need source code.
Tell me if you need source code.
We need source code.
closed account (N36fSL3A)
Download it, Here's the VC++ project. http://www.mediafire.com/?6zhj9eovosxv9od
Last edited on by Fredbill30
closed account (N36fSL3A)
It contains all the graphics needed to build it.
closed account (N36fSL3A)
BUMP
Your problem is in Player::Update().

Player.Health = 1.
1
2
3
4
5
6
7
8
void Player::Update()
{
	while(Health != 0)
	{
		X += Xvel;
		Y += Yvel; //Health is never changed
	} //loop never exits.
}


You have a while loop that never exits.
Btw, Visual Studio has an awesome step-by-step debugger.
Last edited on
closed account (N36fSL3A)
I'm such a ****ing idiot. Wow, thank you.
Well, when I try to run it, it freezes


This probably means you're stuck in an infinite loop somewhere. This is a very easy problem to debug.

When this freeze happens, go into the debugger and tell it to break (in VS, this is the "Break all" option in the "Debug" menu).

The debugger will snap as if you hit a breakpoint. From there you can look at the code being executed and figure out which loop it's getting stuck in and why.


If the debugger snaps and takes you to code that isn't yours, or says it doesn't have the source for whatever file.... then that just means you need to go up in the call stack. Make sure the callstack window is open ("Debug -> Windows -> Call Stack" from the menu) and go down the list until you get to code you recognize).


If you need to, you can step through the code with "Debug -> Step Over" and "Debug -> Step Into" and can look at the contents of any variable with "Debug -> Windows -> Watch" (just type a variable name into the Watch window and it will give you the contents).


This is basic debugging. Now is the time to learn it.


I would look at this myself, but I don't have SDL installed and am too lazy to get it.


EDIT: ninja'd with a solution
Last edited on
closed account (N36fSL3A)
:| Now my program just has a black screen, not drawing ANY of my graphics to the screen.

EDIT: This happens after I deleted the while loop from my program.
Last edited on by Fredbill30
You tell Player to be drawn at (800,600). The screen size is 800x600.
Position of the player where the top left corner of the player image is. If you draw player at that position, the top left pixel of player will appear at the bottom right corner of the screen, and the rest will be located off of the screen.

These are really simple debugging steps. Step through your program and isolate what might be causing the problem. Automatically because graphics aren't being drawn, it's a graphics related issue. Inspect your graphics functions; it's likely they're either not working or you're not using them like you need to be.
Last edited on
closed account (N36fSL3A)
Alright, thanks, I'll be more careful. Since this is kind of solved, I have one more question, can you point me to platformer gravity?
(I didn't intend for my response to sound critical, btw.)

http://www.sdltutorials.com/sdl-collision-events
That sort of goes hand-in-hand with collision detection. iirc, that tutorial talks about making yoshi jump. So that might start you off pretty well.
closed account (N36fSL3A)
Thanks, this is solved officially now :)
Topic archived. No new replies allowed.