Very confused - Platformer
-
- Posts: 20
- Joined: April 17th, 2014, 4:13 am
Very confused - Platformer
Ok, so instead of following the tutorials to build the platformer from chili. I decided i'd try to see how far i could get on my own first and then use the tutorials afterwards, so far it has gone pretty well but i have run in to a very confusing error. After creating a tile class i found that everytime i close the program the compiler runs into a problem on D3D's destructor which is weird because i have not touched the D3Dgraphics class. If i initialize any kind of new surface or tile i get the error upon closing of the program even though the tiles and surfaces render with no issues. For some reason it is unable to properly release the pDevice, i have a feeling it has something to do with the parsing of D3Dgraphics reference to the surface class but i am unsure.
NOTE: the surface class is from the tutorials so i don't think there should be anything wrong with it, i believe the only changes i made was a function to reflect the buffer so that i could draw sprites backwards
NOTE: the surface class is from the tutorials so i don't think there should be anything wrong with it, i believe the only changes i made was a function to reflect the buffer so that i could draw sprites backwards
- Attachments
-
- i iz confuzzled.zip
- (61.02 KiB) Downloaded 132 times
-
- Posts: 5
- Joined: June 20th, 2014, 1:53 pm
Re: Very confused - Platformer
The problem is that the destructor of D3DGraphics is being called for each instance of a surface. This is because you are giving each surface a separate copy of gfx(also creating separate copies of its member pointers.) This means that when each surface deletes its own gfx instance, because its own member pointers of gfx don't yet point to NULL it is trying to release the memory(which of course is empty after the first surface is deleted, hence the error.)
The easiest way to solve this is to store gfx as a pointer in your surface class(this will prevent the D3DGraphics destructor automatically being called when the surfaces are deleted.)
The easiest way to solve this is to store gfx as a pointer in your surface class(this will prevent the D3DGraphics destructor automatically being called when the surfaces are deleted.)
-
- Posts: 20
- Joined: April 17th, 2014, 4:13 am
Re: Very confused - Platformer
Ah of course, if I created multiple instances of the reference they would release the object and then try to do it again, that makes sense. Thanks for your help
Re: Very confused - Platformer
or make the member a reference as wellstagephrite wrote:The easiest way to solve this is to store gfx as a pointer in your surface class(this will prevent the D3DGraphics destructor automatically being called when the surfaces are deleted.)
btw, you'd wanna do "x = xStart" and just "(xEnd - x) - 1" during the flipped draw call (the way you have it setup it discards the last column (which you know is 1st column of non-flipped image lol))
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
-
- Posts: 20
- Joined: April 17th, 2014, 4:13 am
Re: Very confused - Platformer
Yeah i did that on purpose because for whatever reason the last column seemed to be rendering first and there was sort of overlap when the player was running left. That's just a temporary fix, i will come back to debugging it later, but thank you for pointing it out
EDIT: nvm, i just realized what i did. you are right haha
EDIT: nvm, i just realized what i did. you are right haha
Re: Very confused - Platformer
Trying to code yourself instead of just blindly copying what's on the screen is the preferred method of consumption of the tutorials.
Chili
-
- Posts: 20
- Joined: April 17th, 2014, 4:13 am
Re: Very confused - Platformer
Couldn't agree more, i know the code isn't perfect but i learnt a lot from it