I keep getting an access violation with my code in this function..
Code:
#include "stdafx.h"
#include "CSprite.h"
bool CSprite::LoadImage(const std::string &imgfile)
{
SDL_Surface* t_sfc = NULL;
t_sfc = IMG_Load(imgfile.c_str());
if ( t_sfc == NULL )
return false;
spriteSheet = SDL_DisplayFormat(t_sfc); //Access violation here
SDL_FreeSurface(t_sfc);
if ( spriteSheet == NULL )
return false;
return true;
}
this is the class definition...
Code:
#ifndef CSPRITE_H
#define CSPRITE_H
/* CSprite class definition */
class CSprite
{
private:
int x; int y;
int direction;
int xVel; int yVel;
enum
{
UP = 0,
DOWN = 1,
LEFT = 2,
RIGHT = 3
};
SDL_Surface* spriteSheet;
std::vector<SDL_Rect> clips;
public:
CSprite();
~CSprite();
bool LoadImage(const std::string& imgfile);
void NewRect(int x, int y, int w, int h);
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination);
};
#endif
I cant find the problem, but like always it will be something simple.
The exact violation is
Code:
Unhandle exception at 0x68129410 in Varia_Engine.exe: 0xC0000005:
Access violation reading location 0x00000013c.
I am deeply thankful for any assistance. Hopefully I am clear enough.