diff --git a/Assets/uDesktopDuplication/Plugins/x86_64/uDesktopDuplication.dll b/Assets/uDesktopDuplication/Plugins/x86_64/uDesktopDuplication.dll index 8a2fab8..9a666f6 100644 Binary files a/Assets/uDesktopDuplication/Plugins/x86_64/uDesktopDuplication.dll and b/Assets/uDesktopDuplication/Plugins/x86_64/uDesktopDuplication.dll differ diff --git a/Assets/uDesktopDuplication/Scripts/Manager.cs b/Assets/uDesktopDuplication/Scripts/Manager.cs index 67d7534..d350f54 100644 --- a/Assets/uDesktopDuplication/Scripts/Manager.cs +++ b/Assets/uDesktopDuplication/Scripts/Manager.cs @@ -193,8 +193,9 @@ public class Manager : MonoBehaviour for (int i = 0; i < monitorCount; ++i) { if (i == monitors.Count) { monitors.Add(new Monitor(i)); + } else { + monitors[i].Reinitialize(); } - monitors[i].Reinitialize(); } } diff --git a/Assets/uDesktopDuplication/Scripts/Monitor.cs b/Assets/uDesktopDuplication/Scripts/Monitor.cs index 44983c4..04e8a07 100644 --- a/Assets/uDesktopDuplication/Scripts/Monitor.cs +++ b/Assets/uDesktopDuplication/Scripts/Monitor.cs @@ -203,7 +203,7 @@ public class Monitor set; } - private Texture2D errorTexture_; + private static Texture2D errorTexture; private static readonly string errorTexturePath = "uDesktopDuplication/Textures/NotAvailable"; private Texture2D texture_; @@ -212,8 +212,8 @@ public class Monitor get { if (!available) { - return errorTexture_ ?? - (errorTexture_ = Resources.Load(errorTexturePath)); + return errorTexture ?? + (errorTexture = Resources.Load(errorTexturePath)); } if (texture_ == null) { CreateTexture(); @@ -245,11 +245,8 @@ public class Monitor if (texture_) { if (texture_.width != w || texture_.height != h) { - if (texture_) { - Object.Destroy(texture_); - texture_ = null; - } - shouldCreate = true; + Object.DestroyImmediate(texture_); + texture_ = null; } else { shouldCreate = false; } diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp index bdd9a1a..bf82481 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp @@ -18,6 +18,7 @@ Monitor::Monitor(int id) Monitor::~Monitor() { + deskDupl_->Release(); } @@ -118,25 +119,35 @@ void Monitor::Render(UINT timeout) switch (hr) { case DXGI_ERROR_ACCESS_LOST: - // If any monitor setting has changed (e.g. monitor size has changed), - // it is necessary to re-initialize monitors. - Debug::Log("Monitor::Render() => DXGI_ERROR_ACCESS_LOST."); - state_ = State::AccessLost; - break; + { + // If any monitor setting has changed (e.g. monitor size has changed), + // it is necessary to re-initialize monitors. + Debug::Log("Monitor::Render() => DXGI_ERROR_ACCESS_LOST."); + state_ = State::AccessLost; + break; + } case DXGI_ERROR_WAIT_TIMEOUT: - // This often occurs when timeout value is small and it is not problem. - // Debug::Log("Monitor::Render() => DXGI_ERROR_WAIT_TIMEOUT."); - break; + { + // This often occurs when timeout value is small and it is not problem. + // Debug::Log("Monitor::Render() => DXGI_ERROR_WAIT_TIMEOUT."); + break; + } case DXGI_ERROR_INVALID_CALL: - Debug::Error("Monitor::Render() => DXGI_ERROR_INVALID_CALL."); - break; + { + Debug::Error("Monitor::Render() => DXGI_ERROR_INVALID_CALL."); + break; + } case E_INVALIDARG: - Debug::Error("Monitor::Render() => E_INVALIDARG."); - break; + { + Debug::Error("Monitor::Render() => E_INVALIDARG."); + break; + } default: - state_ = State::Unknown; - Debug::Error("Monitor::Render() => Unknown Error."); - break; + { + state_ = State::Unknown; + Debug::Error("Monitor::Render() => Unknown Error."); + break; + } } return; } @@ -159,11 +170,11 @@ void Monitor::Render(UINT timeout) Debug::Error("Monitor::Render() => Texture sizes are defferent."); Debug::Error(" Source : (", srcDesc.Width, ", ", srcDesc.Height, ")"); Debug::Error(" Dest : (", dstDesc.Width, ", ", dstDesc.Height, ")"); - Debug::Log(" => Try modifying width/height using reported value from DDA."); - width_ = srcDesc.Width; - height_ = srcDesc.Height; + //Debug::Log(" => Try modifying width/height using reported value from DDA."); + //width_ = srcDesc.Width; + //height_ = srcDesc.Height; state_ = MonitorState::TextureSizeInconsistent; - SendMessageToUnity(Message::TextureSizeChanged); + //SendMessageToUnity(Message::TextureSizeChanged); } else {