WindowCapture2D icon indicating copy to clipboard operation
WindowCapture2D copied to clipboard

EXCEPTION_ACCESS_VIOLATION occurs when CheckWindowSize is checked and the target window is resized repeatedly

Open mechamogera opened this issue 5 years ago • 2 comments

I found that UE4 crashes with EXCEPTION_ACCESS_VIOLATION when CheckWindowSize is checked and repeated resizing of the target window.

Reproduction steps

  1. Create New UE4.24.2 project and enable WindowCapture2D plugin
  2. Place WindowCapturePlane in the world
  3. Check CheckWindowSize and change CaptureTargetTitle on WindowCapturePlane
  4. Play the project
  5. Resize target window repeatedly

Crash message is

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x08cad000

nvwgf2umx
d3d11
UE4Editor_D3D11RHI!FD3D11DynamicRHI::RHIUpdateTexture2D() [d:\build\++ue4\sync\engine\source\runtime\windows\d3d11rhi\private\d3d11texture.cpp:1805]
UE4Editor_D3D11RHI!FD3D11DynamicRHI::UpdateTexture2D_RenderThread() [d:\build\++ue4\sync\engine\source\runtime\windows\d3d11rhi\private\d3d11texture.cpp:1830]
UE4Editor_Engine!<lambda_d3c33e5a8b9daf3a9ced0d8a29defb66>::operator()() [d:\build\++ue4\sync\engine\source\runtime\engine\private\texture2d.cpp:1417]
UE4Editor_Engine!TGraphTask<TEnqueueUniqueRenderCommandType<`UTexture2D::UpdateTextureRegions'::`34'::UpdateTextureRegionsDataName,<lambda_d3c33e5a8b9daf3a9ced0d8a29defb66> > >::ExecuteTask() [d:\build\++ue4\sync\engine\source\runtime\core\public\async\taskgraphinterfaces.h:847]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4\sync\engine\source\runtime\core\private\async\taskgraph.cpp:686]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4\sync\engine\source\runtime\core\private\async\taskgraph.cpp:583]
UE4Editor_RenderCore!RenderingThreadMain() [d:\build\++ue4\sync\engine\source\runtime\rendercore\private\renderingthread.cpp:340]
UE4Editor_RenderCore!FRenderingThread::Run() [d:\build\++ue4\sync\engine\source\runtime\rendercore\private\renderingthread.cpp:471]
UE4Editor_Core!FRunnableThreadWin::Run() [d:\build\++ue4\sync\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:96]

mechamogera avatar Feb 13 '20 02:02 mechamogera

The following code change worked for me. But i don't understand well.

diff --git a/mnt/d/Program Files/Epic Games/UE_4.24/Engine/Plugins/Marketplace/WindowCapture2D/Source/WindowCapture2D/Private/CaptureMachine.cpp b/WindowCapture2D/Source/WindowCapture2D/Private/CaptureMachine.cpp
index 2fba183..f597966 100755
--- a/mnt/d/Program Files/Epic Games/UE_4.24/Engine/Plugins/Marketplace/WindowCapture2D/Source/WindowCapture2D/Private/CaptureMachine.cpp
+++ b/WindowCapture2D/Source/WindowCapture2D/Private/CaptureMachine.cpp
@@ -82,6 +82,7 @@ bool UCaptureMachine::DoCapture()
 #if PLATFORM_WINDOWS
        if (!m_TargetWindow) return true;
        if (!TextureTarget) return true;
+       if (!m_IsUpdatedTexture) return true;

        if (Properties.CheckWindowSize)
        {
@@ -198,8 +199,12 @@ void UCaptureMachine::UpdateTexture()
 #if PLATFORM_WINDOWS
        if (!TextureTarget) return;

+       m_IsUpdatedTexture = false;
        auto Region = new FUpdateTextureRegion2D(0, 0, 0, 0, TextureTarget->GetSizeX(), TextureTarget->GetSizeY());
-       TextureTarget->UpdateTextureRegions(0, 1, Region, 4 * TextureTarget->GetSizeX(), 4, (uint8*)m_BitmapBuffer);
+       auto Func = [this](uint8* SrcData, const FUpdateTextureRegion2D* Regions) {
+               this->m_IsUpdatedTexture = true;
+       };
+       TextureTarget->UpdateTextureRegions(0, 1, Region, 4 * TextureTarget->GetSizeX(), 4, (uint8*)m_BitmapBuffer, Func);
 #endif
 }

diff --git a/mnt/d/Program Files/Epic Games/UE_4.24/Engine/Plugins/Marketplace/WindowCapture2D/Source/WindowCapture2D/Public/CaptureMachine.h b/WindowCapture2D/Source/WindowCapture2D/Public/CaptureMachine.h
index 0a39c38..6941309 100755
--- a/mnt/d/Program Files/Epic Games/UE_4.24/Engine/Plugins/Marketplace/WindowCapture2D/Source/WindowCapture2D/Public/CaptureMachine.h
+++ b/WindowCapture2D/Source/WindowCapture2D/Public/CaptureMachine.h
@@ -62,6 +62,8 @@ private:
        FIntVector2D m_OriginalWindowSize;
        FIntVector2D m_WindowOffset;

+       bool m_IsUpdatedTexture = true;
+
        class FWCWorkerThread* CaptureWorkerThread = nullptr;
        class FRunnableThread* CaptureThread = nullptr;
 };

mechamogera avatar Feb 14 '20 07:02 mechamogera

Thank you for reporting the phenomenon. I will investigate the cause.

ayumax avatar Feb 14 '20 12:02 ayumax