Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Sat Dec 20, 2014 10:23 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Nov 19, 2009 6:19 am 
Alright, so.

Player is a subclass of VisualGameObject, which is a subclass of BaseObject.

What I'm trying to do is create an object of a player using another class called ApplicationMaster.

It does just fine creating an object of VisualGameObject (line 7 of ApplicationMaster.cpp), but at line 8, it complains. More specifically in the code, look at line 9 of Player.cpp.

Right after the curly bracket in the Player constructor (on the new line), I get the error: Unhandled exception at 0x0041957c in Test.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.

I am using SDL for image and window loading, for what it's worth.

ApplicationMaster.h:
Code:
class ApplicationMaster {

   public:
         ~ApplicationMaster();
         static ApplicationMaster& Instance()
         {
            static ApplicationMaster instance;
            return instance;
         }
         void Startup();
         void Shutdown();
         
   protected:
         ApplicationMaster();
         VisualGameObject* background;
         Player* player1;
};


ApplicationMaster.cpp:
Code:
// ...

void ApplicationMaster::Startup()
{
   try
   {
      background = new VisualGameObject("media/background.jpg");
      player1 = new Player(); //This is where it messes up

   }
   catch (std::string& ex)
   {
   
   }
   
}
// ...


VisualGameObject.h:
Code:
#include <string>
#include <SDL.h>
#include <SDL_image.h>
#include "BaseObject.h"

class VisualGameObject : public BaseObject
{
   public:
         VisualGameObject(const std::string& filename);
         virtual ~VisualGameObject();
         virtual void Draw(SDL_Surface* const mainSurface);
         virtual void Draw(SDL_Surface* const mainSurface, SDL_Rect clip);
         
         
   protected:
         SDL_Surface* surface;
         float x;
         float y;
         
};


Player.h:
Code:
#include "VisualGameObject.h"

class Player :
   public VisualGameObject
{
public:
   Player();
   ~Player();
   SDL_Rect clipBounds;

   void KeyDown(SDL_Event& sdlEvent);
   void KeyUp(SDL_Event& sdlEvent);
   void KeyEvents(SDL_Event& sdlEvent);
   virtual void Draw(SDL_Surface* const mainSurface);
   //virtual void Draw(SDL_Surface* const mainSurface, SDL_Rect clip);
   virtual void EnterFrame(float dt);

protected:
   //SDL_Rect clipBounds;
   float xGo;
   float yGo;

};


Player.cpp:
Code:
#include "Player.h"
#include "Constants.h"

Player::Player() :
   VisualGameObject("media/joe_mac.png"),
   xGo(0),
   yGo(0)
{
// Unhandled exception at 0x0041957c in Test.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.

   /*
      clipBounds.x = 0;
      clipBounds.y = 0;
      clipBounds.w = 20;
      clipBounds.h = 20;
   */
}


If there any other snippets you might want to look at, let me know.

I'd appreciate any help at all, as I am out of ideas.


Top
  
 
 Post subject:
PostPosted: Thu Nov 19, 2009 12:52 pm 
Game Programming Guru

Joined: Sun Aug 15, 2004 6:20 pm
Posts: 1091
Can you provide the definition to VisualGameObject::VisualGameObject(const std::string& filename);? Preferably VisualGameObject.cpp if possible.

_________________
Heard in #gpwiki: <wzl> is there some serious grammar fail in your line or am i just too intelligent for your logic


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 20, 2009 8:25 am 
Shake'n'Baker
User avatar

Joined: Fri Sep 21, 2007 3:35 am
Posts: 58
In debug mode allocated memory is initialized to `0xcdcdcdcd` this is to help you by letting you know you forgot to initialize something, this value is non-NULL and not a valid memory pointer.

Check your code for uninitialized pointers and at least initialize them to NULL.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group