Very confused - Platformer

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
MagicFlyingGoat
Posts: 20
Joined: April 17th, 2014, 4:13 am

Very confused - Platformer

Post by MagicFlyingGoat » July 10th, 2014, 12:37 am

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
Attachments
i iz confuzzled.zip
(61.02 KiB) Downloaded 132 times

stagephrite
Posts: 5
Joined: June 20th, 2014, 1:53 pm

Re: Very confused - Platformer

Post by stagephrite » July 10th, 2014, 5:59 pm

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.)

MagicFlyingGoat
Posts: 20
Joined: April 17th, 2014, 4:13 am

Re: Very confused - Platformer

Post by MagicFlyingGoat » July 10th, 2014, 9:41 pm

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 :D

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Very confused - Platformer

Post by LuisR14 » July 10th, 2014, 10:36 pm

stagephrite 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.)
or make the member a reference as well :)
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 :mrgreen: --

MagicFlyingGoat
Posts: 20
Joined: April 17th, 2014, 4:13 am

Re: Very confused - Platformer

Post by MagicFlyingGoat » July 11th, 2014, 3:18 am

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 :D

EDIT: nvm, i just realized what i did. you are right haha :P

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Very confused - Platformer

Post by chili » July 12th, 2014, 11:23 am

Trying to code yourself instead of just blindly copying what's on the screen is the preferred method of consumption of the tutorials. ;)
Chili

MagicFlyingGoat
Posts: 20
Joined: April 17th, 2014, 4:13 am

Re: Very confused - Platformer

Post by MagicFlyingGoat » July 13th, 2014, 10:40 am

Couldn't agree more, i know the code isn't perfect but i learnt a lot from it :P

Post Reply