diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index fcc0f9a24b..8cc29442ca 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -2451,7 +2451,21 @@ fDesktop->LockSingleWindow(); } default: - _DispatchViewDrawingMessage(code, link); + // The drawing code handles allocation failures using exceptions; + // so we need to account for that here. + try { + _DispatchViewDrawingMessage(code, link); + } catch (std::bad_alloc&) { + // Cancel any message we were in the middle of sending. + fLink.CancelMessage(); + + if (link.NeedsReply()) { + // As done in _DispatchViewDrawingMessage, send just a + // single status_t as the reply. + fLink.StartMessage(B_NO_MEMORY); + fLink.Flush(); + } + } break; } }