Jump to content
  • Advertisement
Sign in to follow this  
sarim

Unhandled Exception

This topic is 2515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color=#000000][font=Verdana, Arial, Helvetica, sans-serif]

I dont know what im doing wrong but for some reason I keep getting an unhandled exception my my entity manager. I try to draw the sprite to the screen and right before the entity manager updates and trys to draw it everything is fine. But as soon as it attempts to draw the sprite i get an exception. Here's the code. Can someone please help me ? This is driving me nuts icon_sad.gif if you need the whole project just let me know and ill email it to you

//Game.cpp [/font]

[color=#000000][size=2]Code:
#include "EntityManager.h"

void System::Init()
{
engine = new System();

engine -> SetWindow(800, 600, "Test");

Entity player;
player.Load("test.png", 100, 100);

manager.Add(player);
}

void System::Run()
{
sf::Event ev;

while (engine -> window -> IsOpened())
{
engine -> window -> PollEvent(ev);


engine -> window -> Clear();
manager.Update();
engine -> window -> Display();
}
}


[color=#000000][font=Verdana, Arial, Helvetica, sans-serif]

//System.cpp [/font]

[color=#000000][size=2]Code:
#include "System.h"

void System::SetScreenDim(int width, int height)
{
this -> SCREENW = width;
this -> SCREENH = height;
}

void System::SetTitle(std::string title)
{
this -> Title = title;
}

void System::SetWindow(int width, int height, std::string title)
{
this -> SCREENW = width;
this -> SCREENH = height;
this -> window = new sf::RenderWindow(sf::VideoMode(width, height), title.c_str());
}


[color=#000000][font=Verdana, Arial, Helvetica, sans-serif]

//EntityManager.cpp [/font]

[color=#000000][size=2]Code:
#include "EntityManager.h"
#include "System.h"

void Manager::Update()
{
Entity entity;

std::list<Entity>::iterator iter = eList.begin();

while (iter != eList.end())
{
entity = *iter;

entity.GetSprite().SetPosition(entity.GetX(), entity.GetY());

engine -> window -> Draw(entity.GetSprite());

iter++;
}
}

void Manager::Add(Entity entity)
{
eList.push_back(entity);
}


[color=#000000][font=Verdana, Arial, Helvetica, sans-serif]

//Entity.cpp [/font]

[color=#000000][size=2]Code:
#include "Entity.h"

void Entity::Load(std::string filename, float x, float y)
{
this -> Filename = filename;

this -> Image.LoadFromFile(this -> Filename.c_str());
this -> Sprite.SetImage(this -> Image);

this -> posx = x;
this -> posy = y;
}

void Entity::Update()
{
this -> Sprite.SetPosition(this -> posx, this -> posy);
}
[color=#000000][font=Verdana, Arial, Helvetica, sans-serif]

[/font]

Share this post


Link to post
Share on other sites
Advertisement
by the way...sorry about the code. I dont know why it didnt come out in proper form :( I didn't mean to do that

Share this post


Link to post
Share on other sites
it has something to do with engine -> window -> Draw(entity.GetSprite());

it says that the value there is something like 0x00000 even tho right before that line the pointer has a value

Share this post


Link to post
Share on other sites
i just ran it again and for some reason "engine" just stops pointing to something altogether. it reads 0x000000etc

Share this post


Link to post
Share on other sites
i am right now but i haven't been programming for a while and i just got back into it seriously a few days ago. I still remember alot its just that im a bit rusty so it's hard for me to weed out little mistakes like that :P

Share this post


Link to post
Share on other sites
Ok so i figured something out...right before "manager.Update()" is called in Run(), "engine" is fine. But inside the "manager.Update()" method it loses its values it's pointing to for some reason. Any idea as to why this is?

Share this post


Link to post
Share on other sites
You can never really master programming in my opinion, because there's always something to learn haha. We all make mistakes. In fact, I'm working on a game, and it seems like for any one thing I implement, there's an error that takes me forever to solve. Then again, I'm self taught, and I tackled big project too early.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!