Fix crash on leftover window handle inside an input device events queue
This commit is contained in:
@@ -89,17 +89,6 @@ Delegate<StringView> Input::AxisValueChanged;
|
||||
Array<ActionConfig> Input::ActionMappings;
|
||||
Array<AxisConfig> Input::AxisMappings;
|
||||
|
||||
void ClearWindowInputs(Window* window)
|
||||
{
|
||||
WindowsManager::WindowsLocker.Lock();
|
||||
for (int32 i = InputEvents.Count() - 1; i >= 0; i--)
|
||||
{
|
||||
if (InputEvents[i].Target == window)
|
||||
InputEvents.RemoveAtKeepOrder(i);
|
||||
}
|
||||
WindowsManager::WindowsLocker.Unlock();
|
||||
}
|
||||
|
||||
void InputSettings::Apply()
|
||||
{
|
||||
PROFILE_MEM(Input);
|
||||
@@ -934,9 +923,10 @@ void InputService::Update()
|
||||
Input::GamepadsChanged();
|
||||
}
|
||||
|
||||
WindowsManager::WindowsLocker.Lock();
|
||||
|
||||
// Pick the first focused window for input events
|
||||
Window* defaultWindow = nullptr;
|
||||
WindowsManager::WindowsLocker.Lock();
|
||||
for (auto window : WindowsManager::Windows)
|
||||
{
|
||||
if (window->IsFocused() && window->GetSettings().AllowInput)
|
||||
@@ -945,6 +935,15 @@ void InputService::Update()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove events from destroyed windows
|
||||
for (int32 i = InputEvents.Count() - 1; i >= 0; i--)
|
||||
{
|
||||
const auto& e = InputEvents[i];
|
||||
if (e.Target && !WindowsManager::Windows.Contains(e.Target))
|
||||
InputEvents.RemoveAtKeepOrder(i);
|
||||
}
|
||||
|
||||
WindowsManager::WindowsLocker.Unlock();
|
||||
|
||||
// Send input events for the focused window
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
#include "Engine/Scripting/ManagedCLR/MMethod.h"
|
||||
#include "Engine/Scripting/ManagedCLR/MClass.h"
|
||||
|
||||
extern void ClearWindowInputs(Window* window);
|
||||
|
||||
#if USE_CSHARP
|
||||
// Helper macros for calling C# events
|
||||
#define BEGIN_INVOKE_EVENT(name, paramsCount) \
|
||||
@@ -124,7 +122,6 @@ WindowBase::WindowBase(const CreateWindowSettings& settings)
|
||||
|
||||
WindowBase::~WindowBase()
|
||||
{
|
||||
ClearWindowInputs((Window*)this);
|
||||
ASSERT(!RenderTask);
|
||||
ASSERT(!_swapChain);
|
||||
WindowsManager::Unregister((Window*)this);
|
||||
@@ -186,7 +183,6 @@ String WindowBase::ToString() const
|
||||
void WindowBase::OnDeleteObject()
|
||||
{
|
||||
// Dereference window
|
||||
ClearWindowInputs((Window*)this);
|
||||
#if !USE_EDITOR
|
||||
if (RenderTask && RenderTask == MainRenderTask::Instance)
|
||||
{
|
||||
|
||||
@@ -181,13 +181,7 @@ WindowsWindow::~WindowsWindow()
|
||||
{
|
||||
if (HasHWND())
|
||||
{
|
||||
// Destroy window
|
||||
if (DestroyWindow(_handle) == 0)
|
||||
{
|
||||
LOG(Warning, "DestroyWindow failed! Error: {0:#x}", GetLastError());
|
||||
}
|
||||
|
||||
// Clear
|
||||
DestroyWindow(_handle);
|
||||
_handle = nullptr;
|
||||
_visible = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user