fix unity log call from native.
This commit is contained in:
@@ -4,15 +4,19 @@
|
||||
#include "Debug.h"
|
||||
|
||||
|
||||
decltype(Debug::mode_) Debug::mode_ = Debug::Mode::File;
|
||||
decltype(Debug::logFunc_) Debug::logFunc_ = nullptr;
|
||||
decltype(Debug::errFunc_) Debug::errFunc_ = nullptr;
|
||||
decltype(Debug::fs_) Debug::fs_;
|
||||
decltype(Debug::ss_) Debug::ss_;
|
||||
decltype(Debug::isInitialized_) Debug::isInitialized_ = false;
|
||||
decltype(Debug::mode_) Debug::mode_ = Debug::Mode::File;
|
||||
decltype(Debug::logFunc_) Debug::logFunc_ = nullptr;
|
||||
decltype(Debug::errFunc_) Debug::errFunc_ = nullptr;
|
||||
decltype(Debug::fs_) Debug::fs_;
|
||||
decltype(Debug::ss_) Debug::ss_;
|
||||
|
||||
|
||||
void Debug::Initialize()
|
||||
{
|
||||
if (isInitialized_) return;
|
||||
isInitialized_ = true;
|
||||
|
||||
if (mode_ == Mode::File)
|
||||
{
|
||||
fs_.open("uDesktopDuplication.log");
|
||||
@@ -23,6 +27,9 @@ void Debug::Initialize()
|
||||
|
||||
void Debug::Finalize()
|
||||
{
|
||||
if (!isInitialized_) return;
|
||||
isInitialized_ = false;
|
||||
|
||||
if (mode_ == Mode::File)
|
||||
{
|
||||
Debug::Log("Stop");
|
||||
|
||||
@@ -64,8 +64,12 @@ private:
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case Level::Log : logFunc_(ss_.str().c_str()); break;
|
||||
case Level::Error : errFunc_(ss_.str().c_str()); break;
|
||||
case Level::Log :
|
||||
if (logFunc_) logFunc_(ss_.str().c_str());
|
||||
break;
|
||||
case Level::Error :
|
||||
if (errFunc_) errFunc_(ss_.str().c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -119,6 +123,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static bool isInitialized_;
|
||||
static Mode mode_;
|
||||
static std::ofstream fs_;
|
||||
static std::ostringstream ss_;
|
||||
|
||||
@@ -25,7 +25,7 @@ std::queue<Message> g_messages;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API InitializeUDD()
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Initialize()
|
||||
{
|
||||
if (g_unity && !g_manager)
|
||||
{
|
||||
@@ -34,7 +34,7 @@ extern "C"
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API FinalizeUDD()
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Finalize()
|
||||
{
|
||||
if (!g_manager) return;
|
||||
|
||||
@@ -52,12 +52,12 @@ extern "C"
|
||||
{
|
||||
case kUnityGfxDeviceEventInitialize:
|
||||
{
|
||||
InitializeUDD();
|
||||
Initialize();
|
||||
break;
|
||||
}
|
||||
case kUnityGfxDeviceEventShutdown:
|
||||
{
|
||||
FinalizeUDD();
|
||||
Finalize();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,6 @@ extern "C"
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
|
||||
{
|
||||
g_unity = unityInterfaces;
|
||||
InitializeUDD();
|
||||
|
||||
auto unityGraphics = g_unity->Get<IUnityGraphics>();
|
||||
unityGraphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
||||
}
|
||||
@@ -76,8 +74,6 @@ extern "C"
|
||||
{
|
||||
auto unityGraphics = g_unity->Get<IUnityGraphics>();
|
||||
unityGraphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
||||
|
||||
FinalizeUDD();
|
||||
g_unity = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user