Skip to content

Commit

Permalink
Add code to react on mouse, pen and touch input events
Browse files Browse the repository at this point in the history
This commit adds the code that is necessary to react on mouse, pen and
touch events. However, it does not actually execute code when such an
event occurs. It was purely added to reproduce the issue described in
[1] which occurs as soon as the version of the Windows App SDK NuGet
packages is raised to a version > 1.1.5 and <= 1.3.230602002.

[1]: microsoft/microsoft-ui-xaml#7924
  • Loading branch information
ackh committed Jun 22, 2023
1 parent c493673 commit a2b9071
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
25 changes: 25 additions & 0 deletions SwapChainPanelBugRepro/View/SquareView.cpp
Expand Up @@ -6,6 +6,7 @@
namespace winrt::SwapChainPanelBugRepro::implementation
{
using namespace winrt::Microsoft::UI::Dispatching;
using namespace winrt::Microsoft::UI::Input;
using namespace winrt::Windows::Foundation;


Expand Down Expand Up @@ -38,6 +39,7 @@ namespace winrt::SwapChainPanelBugRepro::implementation
CreateDeviceResources();
CreateSizeDependentResources();
StartRenderingLoop();
StartInputProcessingLoop();
co_return;
}

Expand All @@ -46,6 +48,7 @@ namespace winrt::SwapChainPanelBugRepro::implementation
{
_isRenderLoopRunning = false;
co_await _renderLoopController.ShutdownQueueAsync();
co_await _inputProcessingLoopController.ShutdownQueueAsync();
co_return;
}

Expand All @@ -67,9 +70,31 @@ namespace winrt::SwapChainPanelBugRepro::implementation
}


void SquareView::StartInputProcessingLoop()
{
if(!_inputProcessingLoopController)
{
_inputProcessingLoopController = DispatcherQueueController::CreateOnDedicatedThread();
_inputProcessingLoopController.DispatcherQueue().TryEnqueue([this]()
{
InputPointerSource inputPointerSource = CreateCoreIndependentInputSource(_pointerSourceDevices);
inputPointerSource.PointerPressed({ this, &SquareView::OnPointerPressed });
});
}
}


void SquareView::Render()
{
_renderer->RenderFrame();
Present();
}


void SquareView::OnPointerPressed(IInspectable const&, PointerEventArgs)
{
// Normally, in here we would process mouse, pen, etc. input and execute code accordingly.
// However, the mere presence of the input processing loop leads to an exception when
// cleaning up the SwapChainPanel.
}
}
9 changes: 9 additions & 0 deletions SwapChainPanelBugRepro/View/SquareView.h
Expand Up @@ -13,6 +13,12 @@ namespace winrt::SwapChainPanelBugRepro::implementation
std::unique_ptr<::SwapChainPanelBugRepro::SquareRenderer> _renderer;

winrt::Microsoft::UI::Dispatching::DispatcherQueueController _renderLoopController{ nullptr };
winrt::Microsoft::UI::Dispatching::DispatcherQueueController _inputProcessingLoopController{ nullptr };

static constexpr auto _pointerSourceDevices =
winrt::Microsoft::UI::Input::InputPointerSourceDeviceKinds::Mouse |
winrt::Microsoft::UI::Input::InputPointerSourceDeviceKinds::Touch |
winrt::Microsoft::UI::Input::InputPointerSourceDeviceKinds::Pen;

bool _isRenderLoopRunning = false;

Expand All @@ -23,7 +29,10 @@ namespace winrt::SwapChainPanelBugRepro::implementation
winrt::Windows::Foundation::IAsyncAction BeforeUnloaded() override;

void StartRenderingLoop();
void StartInputProcessingLoop();
void Render();

void OnPointerPressed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Input::PointerEventArgs e);
};
}

Expand Down
25 changes: 25 additions & 0 deletions SwapChainPanelBugRepro/View/TriangleView.cpp
Expand Up @@ -6,6 +6,7 @@
namespace winrt::SwapChainPanelBugRepro::implementation
{
using namespace winrt::Microsoft::UI::Dispatching;
using namespace winrt::Microsoft::UI::Input;
using namespace winrt::Windows::Foundation;


Expand Down Expand Up @@ -38,6 +39,7 @@ namespace winrt::SwapChainPanelBugRepro::implementation
CreateDeviceResources();
CreateSizeDependentResources();
StartRenderingLoop();
StartInputProcessingLoop();
co_return;
}

Expand All @@ -46,6 +48,7 @@ namespace winrt::SwapChainPanelBugRepro::implementation
{
_isRenderLoopRunning = false;
co_await _renderLoopController.ShutdownQueueAsync();
co_await _inputProcessingLoopController.ShutdownQueueAsync();
co_return;
}

Expand All @@ -67,9 +70,31 @@ namespace winrt::SwapChainPanelBugRepro::implementation
}


void TriangleView::StartInputProcessingLoop()
{
if(!_inputProcessingLoopController)
{
_inputProcessingLoopController = DispatcherQueueController::CreateOnDedicatedThread();
_inputProcessingLoopController.DispatcherQueue().TryEnqueue([this]()
{
InputPointerSource inputPointerSource = CreateCoreIndependentInputSource(_pointerSourceDevices);
inputPointerSource.PointerPressed({ this, &TriangleView::OnPointerPressed });
});
}
}


void TriangleView::Render()
{
_renderer->RenderFrame();
Present();
}


void TriangleView::OnPointerPressed(IInspectable const&, PointerEventArgs)
{
// Normally, in here we would process mouse, pen, etc. input and execute code accordingly.
// However, the mere presence of the input processing loop leads to an exception when
// cleaning up the SwapChainPanel.
}
}
9 changes: 9 additions & 0 deletions SwapChainPanelBugRepro/View/TriangleView.h
Expand Up @@ -13,6 +13,12 @@ namespace winrt::SwapChainPanelBugRepro::implementation
std::unique_ptr<::SwapChainPanelBugRepro::TriangleRenderer> _renderer;

winrt::Microsoft::UI::Dispatching::DispatcherQueueController _renderLoopController{ nullptr };
winrt::Microsoft::UI::Dispatching::DispatcherQueueController _inputProcessingLoopController{ nullptr };

static constexpr auto _pointerSourceDevices =
winrt::Microsoft::UI::Input::InputPointerSourceDeviceKinds::Mouse |
winrt::Microsoft::UI::Input::InputPointerSourceDeviceKinds::Touch |
winrt::Microsoft::UI::Input::InputPointerSourceDeviceKinds::Pen;

bool _isRenderLoopRunning = false;

Expand All @@ -23,7 +29,10 @@ namespace winrt::SwapChainPanelBugRepro::implementation
winrt::Windows::Foundation::IAsyncAction BeforeUnloaded() override;

void StartRenderingLoop();
void StartInputProcessingLoop();
void Render();

void OnPointerPressed(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Input::PointerEventArgs e);
};
}

Expand Down
1 change: 1 addition & 0 deletions SwapChainPanelBugRepro/pch.h
Expand Up @@ -15,6 +15,7 @@

#include <microsoft.ui.xaml.media.dxinterop.h>
#include <winrt/Microsoft.UI.Dispatching.h>
#include <winrt/Microsoft.UI.Input.h>
#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
#include <winrt/Microsoft.UI.Xaml.Markup.h>
#include <winrt/Microsoft.UI.Xaml.Media.h>
Expand Down

0 comments on commit a2b9071

Please sign in to comment.