我正在尝试调试一些有exc_bad_access崩溃的代码。看来我有一个僵尸,但我无法弄清楚为什么对象被解除分配。这是一个针对iOS构建的Unity3D项目。有问题的代码是.mm文件,所以ObjectiveC ++。
因此,仪器显示正在解除分配的功能,但我并不真正了解正在发生的事情。 Responsible Caller是一个名为LoadVideo的函数,它包含在一个'extern“C”中。代码如下:
extern "C"
{
void LoadVideo()
{
// get the current UIViewController
UIViewController *viewController = UnityGetGLViewController();
// create the videLoader object
VideoLoaderUIObject * vidLoader = [VideoLoaderUIObject new];
// start up our loading screen
gSavingVideoAlert = [[CustomIOS7AlertView alloc] init];
UIView* uiViewLoading = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 125)];
UILabel* loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 40)];
loadingLabel.numberOfLines = 2;
[loadingLabel setText:@"Loading videos\nPlease Wait..."];
[loadingLabel setTextAlignment:NSTextAlignmentCenter];
[loadingLabel setTextColor:[UIColor blackColor]];
[loadingLabel setBackgroundColor:[UIColor clearColor]];
[loadingLabel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 14.0f]];
[uiViewLoading addSubview:loadingLabel];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(uiViewLoading.bounds.size.width / 2, uiViewLoading.bounds.size.height - 50);
[indicator startAnimating];
[uiViewLoading addSubview:indicator];
[gSavingVideoAlert setContainerView:uiViewLoading];
[gSavingVideoAlert show];
// open the media gallery
[vidLoader startMediaBrowserFromViewController: viewController usingDelegate: vidLoader];
#ifdef DEBUG_LOGS
NSLog(@"video path %@", [vidLoader VideoPath]);
#endif
}
}
问题似乎出现在这一行:
[vidLoader startMediaBrowserFromViewController: viewController usingDelegate: vidLoader];
vidLoader对象来自VideoLoaderUIObject类,定义为:
@interface VideoLoaderUIObject : UIImagePickerController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
@private
bool mIsUsingCam;
NSMutableArray* mAssets;
NSMutableArray *mVidIPod;
NSMutableArray *mVidItems;
std::vector<UIInterfaceOrientation> mVidOrientations;
MyCustomViewController* mScrollViewController;
}
Instruments的输出如下:
什么阻止了vidLoader对象被保留?