Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: does this make any sense to you? (straaaange)  (Read 2204 times)

0 Members and 1 Guest are viewing this topic.

stevend

  • Newbie
  • *
  • Posts: 20
    • View Profile
does this make any sense to you? (straaaange)
« on: February 09, 2009, 02:52:27 am »
ok so here is my issue; the debugger states that when i execute this code that it goes BACK one statement and therefore creating an infinite loop.

Code: [Select]

ImageManager()->AddImage("bg1", myimage);


That above line equals this:
Code: [Select]
int AddImage (string name, image * myimage) { images.push_back(myimage); names.push_back(name); return images.size(); };

all i am trying to do is add my custom class which hols an instance of sf::Image to an array.

when i remove this code and give the next function the pointer to my image class it works fine, when i try to add it to the array the instruction moves back one (says the debugger) and created an infinate loop. im confused! :P

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
does this make any sense to you? (straaaange)
« Reply #1 on: February 09, 2009, 01:19:07 pm »
The code can't run backwards. ;)
I assume you don't have any goto or even setjmp/longjmp statements? And the shown code isn't located inside a loop?

Are you really sure the debugger jumps back? Do you compile in debug mode? Hmm... You are not accidentally overwriting a function address or something like that? :P (Check your pointers...)

Maybe you could post a little bit more around these two lines... :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

stevend

  • Newbie
  • *
  • Posts: 20
    • View Profile
does this make any sense to you? (straaaange)
« Reply #2 on: February 11, 2009, 12:58:11 pm »
i am also very aware code usually cant just run backwards. but it seems to be jumping back to where the instance of the image was created.

so here is what i did. i made the vector of my class image public.

when i do this:

Code: [Select]

T9::image * myimage = new T9::image("./graphics/metal.jpg");
T9::tec9::Instance()->images.push_back(myimage);


after i call push_back on images, it goes back to where my image was created. creating an infinite loop! simply pushing the class onto the stack is creating the problem! here is my image class.

Code: [Select]
class image
{
public:

image::image (string filename);

sf::Image * GetImage () { return & Image; };

private:

sf::Image Image;
};



explain that! :P if i comment out the line where i add the image to the array of images, and simply just use it to create a sprite, it works without a hitch:

Code: [Select]

T9::image * myimage = new T9::image("./graphics/metal.jpg");
T9::sprite  mysprite(myimage);
statemanager::AddSprite(T9::States::mainmenu, mysprite);


the above code is located on initialization of a manager class

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
does this make any sense to you? (straaaange)
« Reply #3 on: February 11, 2009, 02:19:49 pm »
Do you implement a copy constructor in your image class?
Laurent Gomila - SFML developer

stevend

  • Newbie
  • *
  • Posts: 20
    • View Profile
does this make any sense to you? (straaaange)
« Reply #4 on: February 11, 2009, 04:03:50 pm »
ok well i have an image class which holds a sf::image

i create an instance of this class as a reference so it is not destroyed when the function exits.

i pass a pointer to this class to the sprite class so that it can access the sf::image inside the image class

im trying to store pointers to all created images inside an array, wouldent creating an instance of the image, then copying the whole thing into an array be too time consuming? why not just pass around a pointer to the image.