Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Strange dbLoadImage problem

Author
Message
wtfsven
13
Years of Service
User Offline
Joined: 1st Oct 2011
Location:
Posted: 1st Oct 2011 17:59
Hello all. New to the forum.

So here's the deal:
I have 2 classes: SpriteManager and Sprite. SpriteManager stores a bunch of sprites in an std::vector<Sprite>. Sprite has the following code in it's constuctor:


So here's the thing. I have my images in the same directory as my code files (has been working in the past, don't know if that's completely correct or not.) In the code above, if I call dbImageExist() or dbSpriteExist() IN THAT METHOD, then they return 1. Funny thing is, as soon as that method returns and I jump back once in the call stack, it returns zero.

WTF? Why would just stepping up once in the call stack suddenly kill the image? Is there some sort of insane scope issue going on here?

Thanks for any help - Sven

2A6X1B
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 1st Oct 2011 21:10
when you "step up" on the stack and recheck with dbSpriteExist(), are you adding the +1 to the index like you do in your m_index initializer?

JTK
wtfsven
13
Years of Service
User Offline
Joined: 1st Oct 2011
Location:
Posted: 1st Oct 2011 21:16
Yes. And I've even tried testing indexes from 0 to 20 just out of curiosity. The even more strang thing is that if I call it in my main function, it works fine. Just not in my SpriteManager object.

2A6X1B
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 3rd Oct 2011 20:05
Just guessing blind because I don't know the rest of your code, but is there a deletion of the loaded image in the destructor of the sprite class? You store sprites in a vector, but that means you probably create a sprite object and then push it on the vector. This creates a copy and the original sprite variable may go out of scope and get destructed. You may be better off by creating sprites with new and storing their pointers in the vector. Again, this is a guessing game without seeing more of the code.
wtfsven
13
Years of Service
User Offline
Joined: 1st Oct 2011
Location:
Posted: 3rd Oct 2011 21:38
Thats actually exactly what I'm doing, and that would fix it. Thanks, man!

2A6X1B

Login to post a reply

Server time is: 2024-11-19 07:34:17
Your offset time is: 2024-11-19 07:34:17