Sign in to follow this  
WaleedH95

[SDL] SDL_Flip() is causing an error

Recommended Posts

WaleedH95    102
Ok, so I just started SDL yesterday or before yesterday, either way I'm using Microsoft Visual Studio 2010, and I'm following the tutorial on http://www.lazyfoo.net/, and when I build my program I get this error

[quote]Unhandled exception at 0x6812a21b in SDL.exe: 0xC0000005: Access violation reading location 0x00000004.[/quote]

and I know that SDL_Flip() is causing this because there's a green arrow pointed at it when I build it.

Share this post


Link to post
Share on other sites
rip-off    10976
One of your pointers is null. This probably means that you aren't checking for errors in one of your SDL calls, or you are ignoring the error if you do check it.

Can you post your code?

Share this post


Link to post
Share on other sites
WaleedH95    102
Hidden
Um sure, I don't have any comments on it though so it's gonna be a bit clustered, sorry, and I checked but I couldn't find the null pointers.

Share this post


Link to post
WaleedH95    102
Hidden
Um sure, I don't have any comments on it though so it's gonna be a bit clustered, sorry, and I checked but I couldn't find the null pointers.

Headers:

[quote]#include "SDL.h"
#include "SDL_image.h"
#include <string>

using namespace std;

int SCREEN_WIDTH = 640;
int SCREEN_HEIGHT = 480;
int SCREEN_BPP = 32;

SDL_Surface*screen = NULL;
SDL_Surface*background = NULL;
SDL_Surface*foo = NULL;

SDL_Event event;[/quote]

Functions:

[quote]SDL_Surface*load_image(string filename){
SDL_Surface*loadedImage = NULL;
SDL_Surface*optimizedImage = NULL;

loadedImage = IMG_Load(filename.c_str());
if(loadedImage != NULL){
optimizedImage = SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}[/quote]

[quote]void apply_surface(int x, int y, SDL_Surface*source, SDL_Surface*destination){
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source,NULL,destination,&offset);
}[/quote]

[quote]bool init(){
if(SDL_Init(SDL_INIT_EVERYTHING) == -1){
return 1;
}
screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE);

if(screen = NULL){
return false;
}

SDL_WM_SetCaption("Foo says hi!", NULL);

return true;
}[/quote]


[quote]
bool load_files(){
background = load_image("background.png");
foo = load_image("foo.png");

if(background = NULL){
return false;
}
if(foo = NULL){
return false;
}

return true;
}[/quote]


[quote]
void clean_up(){
SDL_FreeSurface(background);
SDL_FreeSurface(foo);

SDL_Quit();
}[/quote]

Main:

[quote]
int main(int argc,char*args[]){
bool quit = false;

if(init() == false){
return true;
}

if(load_files() == -1){
return 1;
}

apply_surface(0,0,background,screen);
apply_surface(280,140,foo,screen);

SDL_Flip(screen);
SDL_GetError();

SDL_Delay(2000);

while(quit = false){
while(SDL_PollEvent(&event)){
if(event.type = SDL_QUIT){
quit = true;
}
}
}
clean_up();
return 0;
}[/quote]

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this