Jump to content

  • Log In with Google      Sign In   
  • Create Account

Unhandled Exception


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
18 replies to this topic

#1 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 02:59 PM

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 Posted Image if you need the whole project just let me know and ill email it to you

//Game.cpp


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();
}
}


//System.cpp

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());
}


//EntityManager.cpp

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);
}


//Entity.cpp

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);
}
[/code]

Sponsor:

#2 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 03:05 PM

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

#3 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 03:06 PM

Are you allocating and deleting memory appropriately? using something that isn't there can do that. what type of exception are you given?

#4 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 03:16 PM

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

#5 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 03:20 PM

i just ran it again and for some reason "engine" just stops pointing to something altogether. it reads 0x000000etc

#6 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 03:22 PM

I can guarantee it has something to do with allocated memory. Really look at your code and make sure you're handling memory properly.

#7 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 03:27 PM

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

#8 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 03:33 PM

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?

#9 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 03:34 PM

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.

#10 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 03:36 PM

Maybe it has somethign to do with your iterator code? I've never used the iterator classes. I've honestly never heard of our seen it before.

#11 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 03:43 PM

well the iterator stuff just makes a container to hold all the characters and objects within the game. Every frame it runs through all the objects and updates them. This is where "engine" keeps losing its pointer for some reason

#12 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 03:48 PM

Make sure you aren't exceeding the amount of allocated objects there are, and make sure the memory for the objects is allocated accordingly.

#13 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 03:50 PM

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

Is this correct? Seems odd.



#14 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 03:53 PM

let me fix that a bit and ill see if it works

#15 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 03:59 PM

so i cleaned that part up a little bit but it still doesnt work. The error is still coming up at "engine -> window -> Draw();"

#16 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 04:03 PM

Well then it has to be the draw function. Take a look. Or perhaps it has to be the getsprite function

#17 Cryptiik   Members   -  Reputation: 440

Like
0Likes
Like

Posted 27 January 2012 - 04:09 PM

No its not that...it has to do something with the "engine" instantiation. It's perfectly fine before it enters the entity manager. Then when it's in it the value goes to 0x0000000

#18 ProvenDantheman   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 January 2012 - 04:27 PM

I don't know what to tell you, I'm sorry.

#19 swiftcoder   Senior Moderators   -  Reputation: 9997

Like
0Likes
Like

Posted 27 January 2012 - 05:58 PM

You should place a data breakpoint on the relevant pointer, so that you can see when it is modified during debugging.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS