From defde893138e0fd483ff0c189d68c9348fc9ddae Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Sat, 1 Jun 2024 09:04:26 -0700 Subject: [PATCH] Fixing crash in darwin framework (#33698) * Fixing crash * Restyled by clang-format * Reminder for future me * Restyled by clang-format --------- Co-authored-by: Restyled.io --- src/darwin/Framework/CHIP/MTRDevice.mm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index eb16b511e2a7b1..2e2acd3069aa6e 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -963,6 +963,7 @@ - (void)_changeInternalState:(MTRInternalDeviceState)state MTR_LOG("%@ internal state change %lu => %lu", self, static_cast(lastState), static_cast(state)); /* BEGIN DRAGONS: This is a huge hack for a specific use case, do not rename, remove or modify behavior here */ + // TODO: This should only be called for thread devices id delegate = _weakDelegate.strongObject; if ([delegate respondsToSelector:@selector(_deviceInternalStateChanged:)]) { dispatch_async(_delegateQueue, ^{ @@ -3650,17 +3651,18 @@ - (BOOL)_deviceHasActiveSubscription { std::lock_guard lock(_lock); + // TODO: This should always return YES for thread devices return HaveSubscriptionEstablishedRightNow(_internalDeviceState); } - (void)_deviceMayBeReachable { - assertChipStackLockedByCurrentThread(); - MTR_LOG("%@ _deviceMayBeReachable called", self); - - [self _triggerResubscribeWithReason:@"SPI client indicated the device may now be reachable" - nodeLikelyReachable:YES]; + // TODO: This should only be allowed for thread devices + [_deviceController asyncDispatchToMatterQueue:^{ + [self _triggerResubscribeWithReason:@"SPI client indicated the device may now be reachable" + nodeLikelyReachable:YES]; + } errorHandler:nil]; } /* END DRAGONS */