From df9815a4be622a3e86ad00e23a18b13152a22937 Mon Sep 17 00:00:00 2001 From: Kyle Neideck Date: Wed, 27 Mar 2019 12:34:20 +1100 Subject: [PATCH] Fix a crash when BGMDevice's volume is changed. I think that, because BGMStatusBarItem::initWithMenu was capturing a weak reference in a C++ lambda as a C++ reference, the C++ reference would be invalid when it was used. The fix to have the lambda capture by value instead. I'm not completely sure why builds from Xcode never crashed or why ASan didn't catch the bug. Maybe the stack memory was just never reused/invalidated with Xcode builds. (And I probably just don't understand how ASan works well enough.) Fixes #202. --- BGMApp/BGMApp/BGMStatusBarItem.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGMApp/BGMApp/BGMStatusBarItem.mm b/BGMApp/BGMApp/BGMStatusBarItem.mm index 2d637fe..218f29b 100644 --- a/BGMApp/BGMApp/BGMStatusBarItem.mm +++ b/BGMApp/BGMApp/BGMStatusBarItem.mm @@ -84,7 +84,7 @@ static CGFloat const kVolumeIconAdditionalVerticalPadding = 0.075; // Update the icon when BGMDevice's volume changes. BGMStatusBarItem* __weak weakSelf = self; - volumeChangeListener = new BGMVolumeChangeListener(audioDevices.bgmDevice, [&] { + volumeChangeListener = new BGMVolumeChangeListener(audioDevices.bgmDevice, [=] { [weakSelf bgmDeviceVolumeDidChange]; }); }