Public Group

I need help with a bug in my program.

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

Recommended Posts

#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif

#include "SDL.h"

int main( int argc, char* argv[] )
{
SDL_Init ( SDL_INIT_VIDEO ) ;
SDL_Surface* screen;
screen = SDL_SetVideoMode ( 1024 , 768 , 0, SDL_FULLSCREEN ) ;
SDL_Surface* pic;
SDL_Rect dest;
dest.x = 500;
dest.y = 400;
int k = 1;

while(k == 1)
{
int b=5
SDL_Event event;
if(b==5)
{
// line of bug         SDL_BlitSurface(pic,NULL,screen,&dest);
}
SDL_Flip(screen);
SDL_PollEvent(&event);

if ( event.type == SDL_QUIT )
{
k = 2;
}

if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
k = 2;
}
}

if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_UP )
{
dest.x +=1;
dest.y +=1;

SDL_BlitSurface(pic,NULL,screen,&dest);
SDL_Flip(screen);
SDL_FreeSurface(pic);

SDL_BlitSurface(pic,NULL,screen,&dest);
SDL_Flip(screen);
}
}
}
//done
return ( 0 ) ;
}


Unhandled exception at 0x100225d0 in paddle ball.exe: 0xC0000005: Access violation reading location 0x00000000. I tried to fix it when I put in an if statment,but that did'nt work.Can someone please tell me how to fix this? BTW: I'm trying to move the image,will this work?

Share on other sites

Needs to be:

I would strongly suggest that you do not release and reload thaat BMP every movement either [smile]. Just load it once, use it as much as you want, then release it at the very end. Take a look at my Starting with SDL tutorial in my sig. It shows how to do this quite well [wink] (It even has the source code!)

Share on other sites
Try debugging and see where it crashes (F5 in VS 6.0).

Matt Hughson

Share on other sites
It still does it,but the only auto left is pic now.I tried
pic = SDL_SetVideoMode(),but it did'nt do anything.

Share on other sites
You should check the result also!

if (! pic) {  cout << "Error: " << SDL_GetError() << endl;  return 1;}

And do the same for the screen variable.

Share on other sites
DOH! Also I need to correct my first post -

Needs to be:

What is happening is that you declare another variable in the same scope as the first variable, so it never reloads the correct bmp. Take out that SDL_Surface* and it should work, if not definitly do what qbic has suggested to make sure the image can be found in the first place. That is an important concept to keep in mind as well.

- Drew

Share on other sites
The image shows up,but when I hit awroo key up it freezes.

Share on other sites
a couple 'o things(from my humble knowledge of SDL):
It will crash if the img is bigger than the window. Check that.

PollEvent(&event);
should be while(SDL_PollEvent(&event)
{
//end this while at the end of the keys checking,at the last if.
}

at the beginning of the source file, put atexit(SDL_Quit);
and change return 0; to exit(0);(I think you need to include stdlib.h or stdio.h).

Share on other sites
Quote:
 Original post by supercrazy7474and change return 0; to exit(0);(I think you need to include stdlib.h or stdio.h).

Actually use both, it is not required, but it is ALWAYS good practice to return back to the OS.

1. 1
2. 2
frob
16
3. 3
4. 4
5. 5
Rutin
10

• 15
• 13
• 14
• 75
• 22
• Forum Statistics

• Total Topics
632145
• Total Posts
3004344

×