Jump to content
  • Advertisement
Sign in to follow this  
WaleedH95

[SDL] SDL_Flip() is causing an error

This topic is 2538 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

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

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
Advertisement
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
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
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:

#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:

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]

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]

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]



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]



void clean_up(){
SDL_FreeSurface(background);
SDL_FreeSurface(foo);

SDL_Quit();
}[/quote]

Main:


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