Unhandled exception with Sprite wrapper class
  • UraniumSlugUraniumSlug August 2011
    I've basically made a wrapper class for the hgeAnimation class to better suit my needs, however when I attempt to create an instance of this class, I get an unhandled exception on the constuctor. I'm going to go ahead and include my cpp file sprite is of hgeAnimation type and texture is of HTEXTURE type. Any help would be much appreciated at this point. I chose not to use the resource manager on purpose.

    I'm getting an Access violation writing location error.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    	Sprite::Sprite() : texture(NULL), sprite(NULL), x(0.0f), y(0.0f)
    {
     
    }
     
    void Sprite::Load(std::string fileName)
    {
    HGE *engine = hgeCreate(HGE_VERSION);
     
    texture = engine->Texture_Load(fileName.c_str());
     
    sprite = new hgeAnimation(texture, 0 , 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
     
    sprite->SetTexture(texture);
     
    engine->Release();
    }
     
    void Sprite::Release()
    {
    HGE *engine = hgeCreate(HGE_VERSION);
     
    if (sprite)
    {
    delete sprite;
    sprite = NULL;
    }
     
    if (texture)
    {
    engine->Texture_Free(texture);
    }
     
    engine->Release();
    }
     
    void Sprite::Draw()
    {
    sprite->Render(x, y);
    }
  • ProfEclipseProfEclipse August 2011
    We'll need to see your Sprite class declaration (header file) and the code where you are trying to construct the Sprite object.
  • UraniumSlugUraniumSlug August 2011
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    #ifndef SPRITE_H
    #define SPRITE_H
     
    #include "Common.h"
     
    namespace Core
    {
    class Sprite
    {
    public:
    Sprite();
     
    void Load(std::string fileName);
    void Release();
    void Draw();
     
    private:
     
    HTEXTURE texture;
    hgeAnimation *sprite;
    float x;
    float y;
    };
    }
     
    #endif
    1
    2
    3
    4
    5
    	void World::Initialise()
    {
    background = new Sprite();
    background->Load(path + "main_bg.png");
    }


    Initialise gets called after System_Start() in main.

    I hope this helps.
  • ProfEclipseProfEclipse August 2011
    I suspect the problem is that you are passing zero for the number of frames, the width, and the height. One of those is probably causing a divide-by-zero error. Why would you want an animation with no frames (and no width or height) anyway?
  • UraniumSlugUraniumSlug August 2011
    I've tried passing 1 into the frames and texture->GetWidth and GetHeight in those parameters and still haven't had any joy.
  • ProfEclipseProfEclipse August 2011
    Are you absolutely sure that texture is not NULL after the Texture_Load call?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion

Who's Online (2)