Make sure to ignore setDeviceControllerDelegate calls on non-running controllers. (#22778)
Otherwise we can end up with null-derefs trying to touch members that
no longer exist.
Fixes https://github.com/project-chip/connectedhomeip/issues/22776
diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm
index 43c2d0e..221b473 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceController.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm
@@ -535,7 +535,11 @@
- (void)setDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate queue:(dispatch_queue_t)queue
{
+ VerifyOrReturn([self checkIsRunning]);
+
dispatch_async(_chipWorkQueue, ^{
+ VerifyOrReturn([self checkIsRunning]);
+
self->_deviceControllerDelegateBridge->setDelegate(self, delegate, queue);
});
}