Jump to content
  • Advertisement
Sign in to follow this  
Nickie

Shares_ptr is releasing object it shouldn't

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

Shares_ptr is releasing object it shouldn't, or at least I don't want to.
Source code: http://code.google.c.../source/browse/

So how things work(to same you some time):
1. I'm using DXUT. When a device is creating it calls a callback.
2. There I call GetAssetData(Resource(...))). It shoud load this file and split it to AssetData structures.(the function is returning list, however it is not fully impl and it can actually return only meshes.)
3. AssetManager uses the Resource Cache to load the file. Then AssetManager is finding a parser which can parse the raw data and create objects of type AssetData(Mesh is actually "child/inherited" of asset data).
4. The file (.ASE is supported for now) is parsed succesfully(I've have followed the whole process everything works fine, at least for the file I'm testing with). The ASE parser have 2 helper objects. AssetDataPtr(boost::shared_ptr<IAssetData>) and AssetDataList(std::list<AssetDataPtr>). During the process it is allocating asset datas and putting them in the list. The current asset data it is working on is stored in AssetDataPtr;
5. Once it is ready the function End of the Parser is called. It is looping through all AssetDatas in the list and calling their Restore() method.(filling vertex and index buffers).
6. Right after Restore is called, for some reason the Mesh is destructed and it gives me runtime error(There is function RestoreCHildren())

OMG while writing this line I remembered why it is destucting it. However I'll post this thread for other ppl if they ever make the same mistake.

My suggestion on the problem: I'm storing the assets in AssetDataPtr. When Restore is called it creates MeshPtr object storing the same pointer. And because of the different types it cannot check/or it isn't programmed to check for other pointers with the same address and it is deleting it.

Edit: I was not right. I was just creating AssetDataPtr(this); I didn't know that shared_ptr cannot work this way ;/ Edited by Nickie

Share this post


Link to post
Share on other sites
Advertisement
You cannot create a shared_ptr (it's shared_ptr by the way, not shares_ptr) twice using the same raw pointer.

You can either use enable_shared_from_this to retrieve the shared_ptr pointer that is managing a pointer using only a raw pointer or you can use boost::intrusive_ptr if the class to manage has some kind of inbuilt reference counting semantics.

Share this post


Link to post
Share on other sites
You cannot create a shared_ptr (it's shared_ptr by the way, not shares_ptr) twice using the same raw pointer.[/quote]
Its type error. I know how to write it;
And I already hae rewritten my interface to accept raw pointers.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!