LibGUI: Ignore failing smo maps in resize event

This can be caused by sending two back-to-back resize requests. When
handling the first, the server may have already replaced the smo key
with a new one.
This commit is contained in:
2026-07-04 08:42:17 +03:00
parent a2691bd70d
commit 652e170da9
2 changed files with 14 additions and 11 deletions

View File

@@ -310,8 +310,16 @@ namespace LibGUI
close(m_epoll_fd); close(m_epoll_fd);
} }
BAN::ErrorOr<void> Window::handle_resize_event(const EventPacket::ResizeWindowEvent& event) BAN::ErrorOr<bool> Window::handle_resize_event(const EventPacket::ResizeWindowEvent& event)
{ {
void* framebuffer_addr = smo_map(event.smo_key);
if (framebuffer_addr == nullptr)
{
if (errno == ENOENT)
return false;
return BAN::Error::from_errno(errno);
}
if (m_framebuffer_smo) if (m_framebuffer_smo)
munmap(m_framebuffer_smo, m_width * m_height * 4); munmap(m_framebuffer_smo, m_width * m_height * 4);
m_framebuffer_smo = nullptr; m_framebuffer_smo = nullptr;
@@ -321,17 +329,13 @@ namespace LibGUI
if (m_root_widget) if (m_root_widget)
TRY(m_root_widget->set_fixed_geometry({ 0, 0, event.width, event.height })); TRY(m_root_widget->set_fixed_geometry({ 0, 0, event.width, event.height }));
void* framebuffer_addr = smo_map(event.smo_key);
if (framebuffer_addr == nullptr)
return BAN::Error::from_errno(errno);
m_framebuffer_smo = static_cast<uint32_t*>(framebuffer_addr); m_framebuffer_smo = static_cast<uint32_t*>(framebuffer_addr);
m_width = event.width; m_width = event.width;
m_height = event.height; m_height = event.height;
invalidate(); invalidate();
return {}; return true;
} }
void Window::wait_events(const timespec* timeout) void Window::wait_events(const timespec* timeout)
@@ -414,12 +418,11 @@ namespace LibGUI
exit(0); exit(0);
break; break;
case PacketType::ResizeWindowEvent: case PacketType::ResizeWindowEvent:
{ if (auto result = handle_resize_event(TRY_OR_BREAK(EventPacket::ResizeWindowEvent::deserialize(packet_span))); result.is_error())
MUST(handle_resize_event(TRY_OR_BREAK(EventPacket::ResizeWindowEvent::deserialize(packet_span)))); return on_socket_error("handle_resize_event");
if (m_resize_window_event_callback) else if (result.value() && m_resize_window_event_callback)
m_resize_window_event_callback(); m_resize_window_event_callback();
break; break;
}
case PacketType::WindowShownEvent: case PacketType::WindowShownEvent:
if (m_window_shown_event_callback) if (m_window_shown_event_callback)
m_window_shown_event_callback(TRY_OR_BREAK(EventPacket::WindowShownEvent::deserialize(packet_span)).event); m_window_shown_event_callback(TRY_OR_BREAK(EventPacket::WindowShownEvent::deserialize(packet_span)).event);

View File

@@ -96,7 +96,7 @@ namespace LibGUI
void on_socket_error(BAN::StringView function); void on_socket_error(BAN::StringView function);
void cleanup(); void cleanup();
BAN::ErrorOr<void> handle_resize_event(const EventPacket::ResizeWindowEvent&); BAN::ErrorOr<bool> handle_resize_event(const EventPacket::ResizeWindowEvent&);
template<typename T> template<typename T>
void send_packet(const T& packet, BAN::StringView function); void send_packet(const T& packet, BAN::StringView function);