首次调用正常,二次打开Vidyo视图触发EXC_BAD_ACCESS错误排查
Hey there, let's break down why you're hitting this EXC_BAD_ACCESS error with the LmiVideoCapturerImplementationAVFoundation zombie instance. The core issue is that your cleanup flow runs synchronously before Vidyo's async operations finish, and you're missing some critical steps to properly release resources.
What's Wrong With Your Current Flow?
Right now, you're calling disconnect, disable, vc = nil, and VCConnectorPkg uninitialize all in sequence in viewDidDisappear. But Vidyo's disconnect is asynchronous—it doesn't immediately tear down the connection or release internal resources like the video capturer. When you jump straight to disabling and releasing the connector, you're yanking the rug out from under the SDK while it's still working with the capturer. Later, when the SDK tries to reference that already-deallocated capturer, you get the zombie error.
Steps You're Missing (And Fixes)
1. Wait for the Disconnect Callback Before Cleaning Up
Vidyo's VCConnector tells you when the disconnect is actually done via the connectorDidDisconnect: delegate method. You need to trigger your cleanup only after this callback fires, not right away in viewDidDisappear.
Here's how to adjust your code:
- (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self]; // Only kick off the disconnect—don't clean up yet! if (self.vc) { [self.vc disconnect]; } } // Implement this VCConnectorDelegate method - (void)connectorDidDisconnect:(VCConnector *)connector reason:(VCConnectorDisconnectReason)reason { // Now that the disconnect is fully done, safe to clean up [self cleanUpVidyoResources]; }
2. Clean Up Resources in the Right Order
In your cleanup method, follow this sequence to make sure all resources are released properly:
- First, explicitly stop the local camera capture to cut off the SDK's link to the capturer
- Then disable the connector to release hardware resources (camera, mic, speaker)
- Clear the delegate reference to prevent the SDK from holding onto your view controller
- Finally, nil out the connector instance
Also, stop calling VCConnectorPkg uninitialize after every call! This method should only be called once in your app's lifecycle—usually when the app is exiting, or when you're sure you'll never use Vidyo again. Calling it after every call messes up the SDK's internal state and causes conflicts when you reinitialize later.
Example cleanup method:
- (void)cleanUpVidyoResources { if (self.vc) { // Stop local camera capture first to release the capturer explicitly [self.vc stopLocalCamera]; // Remove delegate to break SDK's reference to this VC [self.vc setDelegate:nil]; // Disable the connector to release hardware resources [self.vc disable]; // Nil out the connector to release your strong reference self.vc = nil; } // REMOVE THIS LINE FROM PER-CALL CLEANUP: // [VCConnectorPkg uninitialize]; // Only call this once, e.g., in applicationWillTerminate: }
3. Double-Check for Unhandled Delegates/Notifications
Make sure you're not leaving any dangling delegate references or notification observers that could cause the SDK to send messages to your deallocated view controller. You already remove notification observers, but adding the setDelegate:nil step is crucial here.
Quick Recap
- Let Vidyo finish disconnecting via the delegate callback before cleaning up
- Explicitly stop the local camera before disabling the connector
- Don't call
VCConnectorPkg uninitializeafter every call—save it for app shutdown - Always nil out delegates before releasing SDK instances
内容的提问来源于stack exchange,提问作者user2052501

