SDL Unhandled exception

It has an unhandled exception when it tries to update the screen.

#include "SDL.h"
#include <string>

using namespace std;

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

SDL_Surface *World;
SDL_Surface *Hero;
SDL_Surface *Tree;
SDL_Surface *screen;

SDL_Surface *load_image (string filename)
{
SDL_Surface *loadedimage =NULL;

SDL_Surface *optimizedimage =NULL;

loadedimage = SDL_LoadBMP (filename.c_str());

if (loadedimage != NULL)
{
optimizedimage = SDL_DisplayFormat (loadedimage);

SDL_FreeSurface (loadedimage);
}

return optimizedimage;
}

void applysurface (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);
}

int main (int argc, char* args[])
{
SDL_Init (SDL_INIT_EVERYTHING);

screen = SDL_SetVideoMode (SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);

if (screen = NULL)
{
return 1;
}

SDL_WM_SetCaption ("Hello", NULL);

World = load_image ("World.bmp");
Hero = load_image ("Hero.bmp");
Tree = load_image ("Tree.bmp");

applysurface (0, 0, World, screen);
applysurface (400, 300, Hero, screen);
applysurface (120, 50, Tree, screen);

SDL_Flip (screen);
SDL_Delay (2000);

SDL_FreeSurface (World);
SDL_FreeSurface (Hero);
SDL_FreeSurface (Tree);

SDL_Quit();

return 0;
}
Last edited on
1
2
3
4
if (screen = NULL)
{
return 1;
}


This is undoing everything you assigned to the screen before it, so when you try and do SDL_Flip() it crashes.

You need to use == (comparison) not =.
Last edited on
The double equals sign always gets me. Thanks
Topic archived. No new replies allowed.