![]() |
| | #1 |
| Registered User Join Date: Nov 2005
Posts: 627
| Access violation... can't figure it out... 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;
}
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
The exact violation is Code: Unhandle exception at 0x68129410 in Varia_Engine.exe: 0xC0000005: Access violation reading location 0x00000013c. |
| Raigne is offline | |
| | #2 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Apparently you are trying to invoke CSprite::LoadImage through a null pointer. Check the function which calls CSprite::LoadImage. Is it calling it through a pointer to a CSprite? Is this pointer NULL, possibly? |
| brewbuck is offline | |
| | #3 |
| Registered User Join Date: Nov 2005
Posts: 627
| I tested it like this... Code: int main()
{
CSprite n;
n.LoadImage("C:\\BSM.png"); //access violation.
}
|
| Raigne is offline | |
| | #4 |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| Have you initialized SDL properly? Have you set the display flags correctly?
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #5 |
| Registered User Join Date: Nov 2005
Posts: 627
| yea I used SDL_Init(SDL_INIT_EVERYTHING) and it is successful. I can get the image to load into t_sfc, but it will not let me assign the optimized image to spriteSheet. In the debugger spriteSheet just stays NULL |
| Raigne is offline | |
| | #6 |
| Unregistered User Join Date: Jul 2007
Posts: 925
| The file your reading is open maybe, have you tried reading in shared mode?
__________________ GCC 4.4.0, Code::Blocks 8.02, Fedora 11, x64 |
| Yarin is offline | |
| | #7 |
| Registered User Join Date: Jan 2007 Location: Euless, TX
Posts: 135
| Are you sure that SDL_DisplayFormat(t_sfc) returns a pointer value? Maybe check to see if it's NULL? |
| kcpilot is offline | |
| | #8 |
| Registered User Join Date: Nov 2005
Posts: 627
| Ah, yea SDL_DisplayFormat(t_sfc) is NULL, but why? I can't see why it would be. [EDIT] Thanks for the assistance. It was because I was initializing SDL in hardware memory, and my chipset is not valid for running that way. I had to switch to SWSURFACE. Thank again. [/EDIT] Last edited by Raigne; 10-11-2007 at 11:11 AM. |
| Raigne is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Access Violation | Graham Aker | C Programming | 100 | 01-26-2009 08:31 PM |
| Istream::Release access violation? [C++] | A10 | Windows Programming | 10 | 01-13-2009 10:56 PM |
| Access violation when reading a string. | Desolation | C++ Programming | 16 | 05-01-2007 10:25 AM |
| Access Violation Error | Neurofiend | C Programming | 3 | 08-22-2005 06:19 PM |
| Help! CListCtrl access violation | bonkey | Windows Programming | 4 | 11-18-2003 02:40 PM |