Sign in to follow this  

Allowing your resources to flow through your engine without dangers

This topic is 3864 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
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

This topic is 3864 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this