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.
This commit is contained in:
Kyle Neideck 2019-03-27 12:34:20 +11:00
parent 26dd2ee1ab
commit df9815a4be
No known key found for this signature in database
GPG key ID: CAA8D9B8E39EC18C

View file

@ -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];
});
}