diff options
author | Bjarke Bech <bjarke.bech@gmail.com> | 2021-04-22 02:37:36 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-04-21 20:57:39 -0400 |
commit | e67425c7f32d4ea25dfb92e44a9331914ae3d47e (patch) | |
tree | e39e44d63288fb9b4d9ff3259bbd00a3390ab549 | |
parent | 27c91a71d43ea295cac0d6346ba18ba5a67529e9 (diff) | |
download | pugl-e67425c7f32d4ea25dfb92e44a9331914ae3d47e.tar.gz pugl-e67425c7f32d4ea25dfb92e44a9331914ae3d47e.tar.bz2 pugl-e67425c7f32d4ea25dfb92e44a9331914ae3d47e.zip |
MacOS: Fix memory leaks in puglUpdate()
-rw-r--r-- | src/mac.m | 50 |
1 files changed, 26 insertions, 24 deletions
@@ -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; |