During the android package project, the login function was unavailable, and no problems were found in logcat. The problem was found in the last line of log. It turns out that the constructor in the so file is initialized twice!
This Singleton is implemented by inheriting the template (thread security issues are not considered for the moment)
template<class T>
class CSingleT
{
public:
static T * Instance()
{
if (!ms_pObject)
{
ms_pObject = new T;
}
return ms_pObject;
}
static void Create()
{
if (!ms_pObject)
{
ms_pObject = new T;
}
}
static void Destroy()
{
if (ms_pObject)
{
delete ms_pObject;
ms_pObject = NULL;
}
}
static T * Get()
{
return ms_pObject;
}
static void Reset()
{
Destroy();
Create();
}
protected:
static T * ms_pObject;
};
template <class T>
T * CSingleT<T>::ms_pObject = NULL;
The main thread of the game is to directly call the instance () method, and then pass. in so, a static method is used to call instance (). In fact, the result is that the second singleton object will be initialized after the static method is called directly.
At present, the temporary solution is to call the instance method in the main thread by calling the. So static method, so that only one instance object will be generated. This does not involve the problem of multithreading, so there is no full code for thread security.
Using static methods and then calling the instance object is indeed a bad method. This is done for the time being to make the game run.
Refer:
Multiple instances (Linux) appear in single-instance mode between dynamic libraries)
Cross-So (DLL) Problem of template Singleton in C ++: rtti, typeid, static, Singleton
Multiple instantiation of template Singleton in multiple so instances