microsoft / WindowsAppSDK-Samples

Feature samples for the Windows App SDK
MIT License
721 stars 225 forks source link

Marshal OnDirect3DDeviceLost to UI thread. #352

Closed niklasb-ms closed 5 months ago

niklasb-ms commented 5 months ago

Description

This change fixes a thread safety issue with DrawingIsland::OnDirect3DDeviceLost. This method recreates the D2D device and re-renders text items after device lost. The problem is that this method is called from a threadpool thread, not the UI thread. The fix is to use DispatcherQueue to marshal the call to the UI thread.

I tested this by forcing device loss using dxcap -forceTDR and verifying that text still renders correctly. I also verified in the debugger that TextRenderer::RecreateDirect2DDevice is called from the UI thread.

jeffstall commented 5 months ago

Thanks!