Right Hey All!
I am using a nice state manager kindly made by Exploiter.
Something very wierd has been happening.
Whenever I 'New' an object, I cannot do anything with it.. if I try and access its member functions or even delete it, I get access violations...
Example >
Entity.hpp
#pragma once
#include <SFML/Graphics.hpp>
#include <Box2D/Box2D.h>
class Entity
{
public:
Entity(void);
~Entity(void);
sf::Sprite mSprite;
};
Entity.cpp
#include "Entity.h"
Entity::Entity(void)
{
}
Entity::~Entity(void)
{
}
Playstate.hpp
#ifndef PLAYSTATE_HPP
#define PLAYSTATE_HPP
#include <SFML/Graphics.hpp>
#include <Box2D/Box2D.h>
#include "GameState.hpp"
#include "PhysicsManager.h"
#include "Entity.h"
class GameEngine;
class PlayState : public GameState
{
public:
PlayState( GameEngine& game, bool replace = true );
~PlayState();
void pause();
void resume();
void update();
void draw();
private:
PhysicsManager mPhysicsManager;
Entity *mEntity;
};
#endif // PLAYSTATE_HPP
Playstate.cpp
#include <memory>
#include <iostream>
#include "PlayState.hpp"
#include "MenuState.hpp"
#include "GameEngine.hpp"
#include "sGraphicsManager.h"
PlayState::PlayState( GameEngine& game, bool replace ) : GameState( game, replace)
{
std::cout << "PlayState Init" << std::endl;
mPhysicsManager.GetWorld()->SetGravity( b2Vec2(0, 9.4f));
Entity* mEntity = new Entity();
mEntity->mSprite.setPosition(100,100);
}
PlayState::~PlayState()
{
delete mEntity;
//Dtor
}
void PlayState::pause()
{
std::cout << "PlayState Pause" << std::endl;
}
void PlayState::resume()
{
std::cout << "PlayState Resume" << std::endl;
}
void PlayState::update()
{
sf::Event event;
sGraphicsManager *Graphics = sGraphicsManager::Instance();
while( Graphics->GetWindow().pollEvent( event ) )
{
switch( event.type )
{
case sf::Event::Closed:
m_game.quit();
break;
case sf::Event::KeyPressed:
switch( event.key.code )
{
case sf::Keyboard::Escape:
m_game.quit();
break;
case sf::Keyboard::M:
m_next = m_game.build<MenuState>( false );
break;
}
break;
}
}
}
void PlayState::draw()
{
sGraphicsManager *Graphics = sGraphicsManager::Instance();
Graphics->GetWindow().clear( sf::Color(7, 10, 29));
Graphics->GetWindow().display();
}
Now as you can see.. this should work fine? But when I setposition on mEntity - get get access violation? Even if I remove that line, when I close the app, it gets access violation on the mEntity destructor when I delete it..
What the hell??