aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac.m
diff options
context:
space:
mode:
authorBjarke Bech <bjarke.bech@gmail.com>2021-04-22 02:37:36 +0200
committerDavid Robillard <d@drobilla.net>2021-04-21 20:57:39 -0400
commite67425c7f32d4ea25dfb92e44a9331914ae3d47e (patch)
treee39e44d63288fb9b4d9ff3259bbd00a3390ab549 /src/mac.m
parent27c91a71d43ea295cac0d6346ba18ba5a67529e9 (diff)
downloadpugl-e67425c7f32d4ea25dfb92e44a9331914ae3d47e.tar.gz
pugl-e67425c7f32d4ea25dfb92e44a9331914ae3d47e.tar.bz2
pugl-e67425c7f32d4ea25dfb92e44a9331914ae3d47e.zip
MacOS: Fix memory leaks in puglUpdate()
Diffstat (limited to 'src/mac.m')
-rw-r--r--src/mac.m50
1 files changed, 26 insertions, 24 deletions
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;