Skip to content

Commit eddebd6

Browse files
authored
Marshal OnDirect3DDeviceLost to UI thread. (#352)
1 parent 0e07f71 commit eddebd6

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

Samples/Islands/DrawingIsland/DrawingIslandComponents/DrawingIsland.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ namespace winrt::DrawingIslandComponents::implementation
702702
{
703703
// TODO - what is the purpose of this?
704704
UNREFERENCED_PARAMETER(point);
705-
// VisualElement* selectedVisual = HitTestVisual(point);
705+
// auto selectedVisual = HitTestVisual(point);
706706
}
707707

708708
void
@@ -781,17 +781,22 @@ namespace winrt::DrawingIslandComponents::implementation
781781
DeviceLostHelper const* /* sender */,
782782
DeviceLostEventArgs const& /* args */)
783783
{
784-
// Recreate the text renderer's D3D and D2D devices.
785-
m_output.TextRenderer->RecreateDirect2DDevice();
784+
// This call comes in on a Threadpool worker thread, so use the DispatcherQueue
785+
// to marshal the call to the UI thread.
786+
m_island.DispatcherQueue().TryEnqueue(
787+
[this] {
788+
// Recreate the text renderer's D3D and D2D devices.
789+
m_output.TextRenderer->RecreateDirect2DDevice();
786790

787-
// Give each item an opportunity to recreate its device-dependent resources.
788-
for (auto& item : m_items.Items)
789-
{
790-
item->OnDeviceLost();
791-
}
791+
// Give each item an opportunity to recreate its device-dependent resources.
792+
for (auto& item : m_items.Items)
793+
{
794+
item->OnDeviceLost();
795+
}
792796

793-
// Listen for device lost on the new device.
794-
m_output.DeviceLostHelper.WatchDevice(m_output.TextRenderer->GetDevice());
797+
// Listen for device lost on the new device.
798+
m_output.DeviceLostHelper.WatchDevice(m_output.TextRenderer->GetDevice());
799+
});
795800
}
796801

797802

Samples/Islands/DrawingIsland/DrawingIslandComponents/DrawingIslandComponents.vcxproj.filters

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
<ClCompile Include="Item.cpp">
3434
<Filter>Source Files</Filter>
3535
</ClCompile>
36-
<ClCompile Include="DeviceLostHelper.cpp" />
36+
<ClCompile Include="DeviceLostHelper.cpp">
37+
<Filter>Source Files</Filter>
38+
</ClCompile>
3739
</ItemGroup>
3840
<ItemGroup>
3941
<ClInclude Include="pch.h" />

0 commit comments

Comments
 (0)