Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Migrating Pointer to std::shared_ptr in sdk


i would like to implement but i got a crash at closing the application, because of an invalid pointer.
The Problem is that a ProjectFile* is deleted but shared between different objects, and not cleared the right way. Even a comment in the code shows hints to the problem:

--- Code: ---// FIXME This call is rather strange. It advertises that it will close the files, but in fact it
// removes all files from the project, deallocates all ProjectFile instances and returns. This
// leaves the ProjectBuildTarget ProjectFile instances to be dangling. I don't undestand!!!
bool cbProject::CloseAllFiles(bool dontsave)
--- End code ---
In addition to the ProjectBuildTarget  object, also the FileTreeData has a dangling ProjectFile*
This is probably a source of some crashes and bugs.

I think the "easiest" (but a LOT work) solution to fix this would be to use std::shared_ptr and std::weak_ptr.... But this would break a lot code....
One idea is to use internally shared pointer, and introduce some parallel api that returns the shared_ptr but let the old api alone...

Any ideas, suggestions?


[0] Message Index

Go to full version