Assume we have the following class:
Code: Select all
class ClassA {
shared_ptr _this;
ClassA() { }
public static shared_ptr create() {
shared_ptr result = new ClassA();
result._this = result;
return result;
}
};Background Information:
In a method of ClassA we are not able to get the shared_ptr of the instance of this method. The syntax this refers to the class itself and not to the shared_ptr of this class.
I do not know a way to get the shared_ptr of this.
So i used the factory method which modifies the created instance.
Problem:
Code: Select all
shared_ptr _instance;
_instance = ClassA::create();
Code: Select all
shared_ptr _instance;
_instance = ClassA::create();
_instance = ClassA::create();
I think this is due to a double delete on the C++ side, when the first instance is not used anymore and the "destructor" is called. This code tries to get rid of the shared_ptr _this as well and this is the big crash (IMHO)
I hope this will help others to find other solutions.
At my own problem i have found another solution (which has to do with dpConnectUserData and the callback needs to access the shared_ptr).
With best regards
Frank Lindecke