Fix freeze when resizing a window (#239)

Fixed an annoying bug where the application would freeze when resizing
the window
This pull request made it so the SDL window's resizing event now
broadcasts a new event specifically asking the swapchain to recreate
itself, which will in turn broadcast the original event when done. It
also removed the Event enum specific values, as they were irrelevant.
This commit is contained in:
Daemo
2026-08-07 00:18:52 +02:00
committed by GitHub
parent ddfbe32cea
commit 2d0c02ae7e
3 changed files with 9 additions and 8 deletions
+4 -3
View File
@@ -19,9 +19,10 @@ namespace mlx
enum class Event
{
ResizeEventCode = 56,
FrameBeginEventCode = 57,
FatalErrorEventCode = 168,
ResizeEventCode = 1,
SwapchainResizeEventCode,
FrameBeginEventCode,
FatalErrorEventCode,
EndEnum
};
+3 -3
View File
@@ -8,9 +8,9 @@ namespace mlx
{
namespace Internal
{
struct ResizeEventBroadcast : public EventBase
struct SwapchainResizeEventBroadcast : public EventBase
{
Event What() const override { return Event::ResizeEventCode; }
Event What() const override { return Event::SwapchainResizeEventCode; }
};
}
@@ -23,7 +23,7 @@ namespace mlx
if(!m_events_hooks.contains(window_id) || m_events_hooks[window_id][event].empty())
return;
if(event == MLX_WINDOW_EVENT && code == 8)
EventBus::SendBroadcast(Internal::ResizeEventBroadcast{});
EventBus::SendBroadcast(Internal::SwapchainResizeEventBroadcast{});
for(const auto& hook : m_events_hooks[window_id][event])
{
if(hook.fn)
+1 -1
View File
@@ -161,7 +161,7 @@ namespace mlx
std::function<void(const EventBase&)> functor = [this](const EventBase& event)
{
if(event.What() == Event::ResizeEventCode && !m_resize)
if(event.What() == Event::SwapchainResizeEventCode && !m_resize)
m_resize = true;
};
EventBus::RegisterListener({ functor, "mlx_swapchain_" + std::to_string(reinterpret_cast<std::uintptr_t>(this)) });