I've written a function that creates a sprite and returns its address. If i create a pointer and use the function to make it point to this newly created sprite it seems to work. But for some reason during the windows message loop, when peekMessage(); is called, the pointer changes to some random value. I have no idea why it changes, its so strange.
Does anyone have a clue why it would change? Iv'e been banging my head against the desk for hours.
I could upload the solution if anyone wants, i just don't want anyone to laugh at my code.
Pointer changes for no reason.
Pointer changes for no reason.
Musi
There are 10 types of people that understand binary.
Those that do, and those that don't.
There are 10 types of people that understand binary.
Those that do, and those that don't.
Re: Pointer changes for no reason.
Hey Musi!
Could there be a name collision? The peekMessage function returns "A pointer to an MSG structure that receives message information".
Other than that, I think it would be helpful for you to post the solution! I'll be happy to look for you!
-Paradox
Could there be a name collision? The peekMessage function returns "A pointer to an MSG structure that receives message information".
Other than that, I think it would be helpful for you to post the solution! I'll be happy to look for you!
-Paradox
Re: Pointer changes for no reason.
Yessss! I found what was wrong. I was in the middle of tidying up the code and commenting it for you when i noticed it.
I made the function so it just created a normal Sprite object on the stack and returned its address, which is completely wrong because once it leaves the function's scope the computer can do what the hell it likes with that address. What i should have done was create a Sprite pointer and allocate a new one on the heap and then return the pointer, which I've now done, and it works!
Thank you for offering to help Paradox, and for inadvertently helping to solve the problem.
I made the function so it just created a normal Sprite object on the stack and returned its address, which is completely wrong because once it leaves the function's scope the computer can do what the hell it likes with that address. What i should have done was create a Sprite pointer and allocate a new one on the heap and then return the pointer, which I've now done, and it works!
Thank you for offering to help Paradox, and for inadvertently helping to solve the problem.
Musi
There are 10 types of people that understand binary.
Those that do, and those that don't.
There are 10 types of people that understand binary.
Those that do, and those that don't.