Jump to content
  • Advertisement
Sign in to follow this  
Little Coding Fox

Allowing your resources to flow through your engine without dangers

This topic is 4082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone. I'm having a bit of a problem with the way i'm passing resources, which can vary from Graphics Devices to Input/Output FileSystem Handles from plugins to the app's EXE. Before, i was using reference-counted pointers, which worked fine, however, not if i use derived classes from abstract classes. I need to find a proper way to handle my resources to the APP and to let the APP know the resources has "expired" (aka, memory deleted or deconstructed) so i wont get memory access violations. Does anyone know what i should do to do so? As said before, Ref-Counted Pointers work fine IF i'm not sending a derived class from an abstract class to the APP it will work fine, but if i use a derived class it'll just end up crashing in the end for trying to delete it, so reference counted pointers are out of the question. I'm using C++, no .net or anything, just plain old C++. I hope to hear from you guys soon, and hope you have a nice day!

Share this post


Link to post
Share on other sites
Advertisement
Quote:

Does anyone know what i should do to do so? As said before, Ref-Counted Pointers work fine IF i'm not sending a derived class from an abstract class to the APP it will work fine, but if i use a derived class it'll just end up crashing in the end for trying to delete it, so reference counted pointers are out of the question.


Have you considered that this might be because of a buggy smart pointer class or buggy destructors? I don't see any reason why reference counting shouldn't work with subclasses. Before you dismiss reference counting, try out boost::shared_ptr and boost::weak_ptr (www.boost.org).

Share this post


Link to post
Share on other sites
How are your destructors set up? Is the destructor in the base class virtual?


I think it should be fine too. I'd have the smart pointer reference the base class. Calling its destructor would then defer to the derived class's destructor, which in turn cleans up itself, then the base class.


If there really *is* a problem, I'd like to hear more since I'm using smart pointers in my resource management as well, but haven't had a need for any derivation in my resource objects.

Share this post


Link to post
Share on other sites
Maybe its my implementation that has a problem somewhere... I'll check the boost ptrs implementation to see if i'm making any obvious mistakes.

If i do find anything, i'll let you guys know.

Thank you for your replies!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!