Skip to content

Commit 8c390c8

Browse files
committed
More safepointer fixes
1 parent 3c56099 commit 8c390c8

4 files changed

Lines changed: 21 additions & 18 deletions

File tree

Source/Canvas.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,8 +1590,6 @@ void Canvas::deselectAll(bool const broadcastChange)
15901590
s->hideParameters();
15911591

15921592
if (!broadcastChange) {
1593-
// Add back the listener, but make sure it's added back 'after' the last event on the message queue.
1594-
// Guard with a SafePointer: the canvas may be deleted (e.g. its tab closed) before this runs.
15951593
MessageManager::callAsync([_this = SafePointer(this)] {
15961594
if (_this)
15971595
_this->selectedComponents.addChangeListener(_this);
@@ -2563,8 +2561,6 @@ void Canvas::setSelected(Component* component, bool const shouldNowBeSelected, b
25632561
}
25642562

25652563
if (!broadcastChange) {
2566-
// Add back the listener, but make sure it's added back 'after' the last event on the message queue.
2567-
// Guard with a SafePointer: the canvas may be deleted (e.g. its tab closed) before this runs.
25682564
MessageManager::callAsync([_this = SafePointer(this)] {
25692565
if (_this)
25702566
_this->selectedComponents.addChangeListener(_this);

Source/Heavy/DaisyExporter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ class DaisyExporter final : public ExporterBase {
9090
exportingView->showState(result ? ExportingProgressView::BootloaderFlashFailure : ExportingProgressView::BootloaderFlashSuccess);
9191
exportingView->stopMonitoring();
9292

93-
MessageManager::callAsync([this] {
94-
repaint();
93+
MessageManager::callAsync([_this = SafePointer(this)] {
94+
if (_this)
95+
_this->repaint();
9596
});
9697
});
9798
};

Source/Heavy/ExporterBase.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ struct ExporterBase : public Component
287287

288288
exportingView->stopMonitoring();
289289

290-
MessageManager::callAsync([this] {
291-
repaint();
290+
MessageManager::callAsync([_this = SafePointer(this)] {
291+
if (_this)
292+
_this->repaint();
292293
});
293294

294295
FileSystemWatcher::removeGlobalIgnorePath(outPath);

Source/Heavy/ToolchainInstaller.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ class ToolchainInstaller final : public Component
196196
auto success = Decompress::extractTarXz((uint8_t const*)toolchainData.getData(), toolchainData.getSize(), toolchainDir.getParentDirectory(), expectedSize);
197197

198198
if (!success || statusCode >= 400) {
199-
MessageManager::callAsync([this] {
200-
installButton.topText = "Try Again";
201-
errorMessage = "Error: Could not extract downloaded package";
202-
repaint();
203-
stopTimer();
199+
MessageManager::callAsync([_this = SafePointer(this)] {
200+
if (!_this)
201+
return;
202+
_this->installButton.topText = "Try Again";
203+
_this->errorMessage = "Error: Could not extract downloaded package";
204+
_this->repaint();
205+
_this->stopTimer();
204206
});
205207
return;
206208
}
@@ -210,8 +212,9 @@ class ToolchainInstaller final : public Component
210212
File driverSpec = toolchainDir.getChildFile("etc").getChildFile("usb_driver").getChildFile("DFU_in_FS_Mode.inf");
211213

212214
// Since we interact with ComponentPeer, better call it from the message thread
213-
MessageManager::callAsync([this, usbDriverInstaller, driverSpec]() mutable {
214-
OSUtils::runAsAdmin(usbDriverInstaller.getFullPathName().toStdString(), ("install --inf=" + driverSpec.getFullPathName()).toStdString(), editor->getPeer());
215+
MessageManager::callAsync([_this = SafePointer(this), usbDriverInstaller, driverSpec]() mutable {
216+
if (_this)
217+
OSUtils::runAsAdmin(usbDriverInstaller.getFullPathName().toStdString(), ("install --inf=" + driverSpec.getFullPathName()).toStdString(), _this->editor->getPeer());
215218
});
216219
#endif
217220

@@ -239,9 +242,11 @@ class ToolchainInstaller final : public Component
239242
installProgress = 0.0f;
240243
stopTimer();
241244

242-
MessageManager::callAsync([this] {
243-
dialog->setBlockFromClosing(false);
244-
toolchainInstalledCallback();
245+
MessageManager::callAsync([_this = SafePointer(this)] {
246+
if (!_this)
247+
return;
248+
_this->dialog->setBlockFromClosing(false);
249+
_this->toolchainInstalledCallback();
245250
});
246251
}
247252

0 commit comments

Comments
 (0)