From e67425c7f32d4ea25dfb92e44a9331914ae3d47e Mon Sep 17 00:00:00 2001 From: Bjarke Bech Date: Thu, 22 Apr 2021 02:37:36 +0200 Subject: MacOS: Fix memory leaks in puglUpdate() --- src/mac.m | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/mac.m b/src/mac.m index 090dd0f..54aaf02 100644 --- a/src/mac.m +++ b/src/mac.m @@ -1188,36 +1188,38 @@ dispatchClientEvent(PuglWorld* world, NSEvent* ev) PuglStatus puglUpdate(PuglWorld* world, const double timeout) { - NSDate* date = - ((timeout < 0) ? [NSDate distantFuture] - : [NSDate dateWithTimeIntervalSinceNow:timeout]); - - for (NSEvent* ev = NULL; - (ev = [world->impl->app nextEventMatchingMask:NSAnyEventMask - untilDate:date - inMode:NSDefaultRunLoopMode - dequeue:YES]);) { - if ([ev type] == NSApplicationDefined && [ev subtype] == PUGL_CLIENT) { - dispatchClientEvent(world, ev); - } + @autoreleasepool { + NSDate* date = + ((timeout < 0) ? [NSDate distantFuture] + : [NSDate dateWithTimeIntervalSinceNow:timeout]); + + for (NSEvent* ev = NULL; + (ev = [world->impl->app nextEventMatchingMask:NSAnyEventMask + untilDate:date + inMode:NSDefaultRunLoopMode + dequeue:YES]);) { + if ([ev type] == NSApplicationDefined && [ev subtype] == PUGL_CLIENT) { + dispatchClientEvent(world, ev); + } - [world->impl->app sendEvent:ev]; + [world->impl->app sendEvent:ev]; - if (timeout < 0) { - // Now that we've waited and got an event, set the date to now to - // avoid looping forever - date = [NSDate date]; + if (timeout < 0) { + // Now that we've waited and got an event, set the date to now to avoid + // looping forever + date = [NSDate date]; + } } - } - for (size_t i = 0; i < world->numViews; ++i) { - PuglView* const view = world->views[i]; + for (size_t i = 0; i < world->numViews; ++i) { + PuglView* const view = world->views[i]; - if ([[view->impl->drawView window] isVisible]) { - puglDispatchSimpleEvent(view, PUGL_UPDATE); - } + if ([[view->impl->drawView window] isVisible]) { + puglDispatchSimpleEvent(view, PUGL_UPDATE); + } - [view->impl->drawView displayIfNeeded]; + [view->impl->drawView displayIfNeeded]; + } } return PUGL_SUCCESS; -- cgit v1.2.1