diff --git a/Rendering/UI/vtkWin32RenderWindowInteractor.cxx b/Rendering/UI/vtkWin32RenderWindowInteractor.cxx index 8900799ee9e0bec692ee7f62c756c8a2fa45efab..24834c6c7e2cdf5c0e0a95521067411cba5618e3 100644 --- a/Rendering/UI/vtkWin32RenderWindowInteractor.cxx +++ b/Rendering/UI/vtkWin32RenderWindowInteractor.cxx @@ -446,7 +446,13 @@ int vtkWin32RenderWindowInteractor::InternalCreateTimer( { vtkWin32RenderWindowInteractor::TimerContext* data = static_cast<vtkWin32RenderWindowInteractor::TimerContext*>(lpParameter); - PostMessage(data->WindowId, WM_TIMER, data->TimerId, 0); + + // Do not post another message for the same timer if already posted + // to avoid flooding the message queue + if (!data->Posted.exchange(true)) + { + PostMessage(data->WindowId, WM_TIMER, data->TimerId, 0); + } }; std::unique_ptr<vtkWin32RenderWindowInteractor::TimerContext> timerContext( @@ -671,6 +677,7 @@ int vtkWin32RenderWindowInteractor::OnTimer(HWND, UINT timerId) return 0; } int tid = static_cast<int>(timerId); + this->TimerContextMap[timerId]->Posted = false; return this->InvokeEvent(vtkCommand::TimerEvent, &tid); } diff --git a/Rendering/UI/vtkWin32RenderWindowInteractor.h b/Rendering/UI/vtkWin32RenderWindowInteractor.h index 4d512ba0d87fc1fddc23640a8a6c7a7475297833..606244bca9d142ec79ac4a402c938b15a41c7ecd 100644 --- a/Rendering/UI/vtkWin32RenderWindowInteractor.h +++ b/Rendering/UI/vtkWin32RenderWindowInteractor.h @@ -23,6 +23,10 @@ #include "vtkWindows.h" // For windows API. #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO +#include <atomic> // for std::atomic +#include <map> // for std::map +#include <memory> // for std::unique_ptr + #include "vtkTDxConfigure.h" // defines VTK_USE_TDX #ifdef VTK_USE_TDX VTK_ABI_NAMESPACE_BEGIN @@ -188,6 +192,7 @@ private: HWND WindowId; int TimerId; HANDLE PlatformId; + std::atomic<bool> Posted = false; }; std::map<int, std::unique_ptr<TimerContext>> TimerContextMap; };