Problem
Ti.UI.iPhone.NavigationGroup.close()
crashes with EXC_BAD_ACCESS
Test case
When using an unmodified 1.8.20111028x CI build, the following testcase generally crashes with EXC_BAD_ACCESS after 2 to 10 presses of the "Start Test" button.
var root = Ti.UI.createWindow({
title: 'Root Window',
backgroundColor: 'white',
layout: 'vertical',
});
var startButton = Ti.UI.createButton({
title: 'Start Test',
height:'50dp',
width:'200dp',
top:'20dp',
});
startButton.addEventListener('click', function() {
// for (;;) {
var windows = [], n = Math.floor(Math.random() * 10) + 3;
for (var i=0; i < n; i++) {
var w = Ti.UI.createWindow({
title: 'Window '+i,
backgroundColor: 'white',
layout: 'vertical',
});
windows.push(w);
navgroup.open(w, {animated:false});
Ti.API.info('opened '+w.title);
}
while (windows.length > 0) {
var winToClose = windows.pop();
navgroup.close(winToClose, { animated: false});
Ti.API.info('closed '+w.title);
}
// }
});
root.add(startButton);
var navgroup = Ti.UI.iPhone.createNavigationGroup({
window: root
});
var container = Ti.UI.createWindow();
container.add(navgroup);
container.open();
Solution
Running the app under Instruments shows that a message is being sent to a deallocated object in the
createProxy:forName:context: method in TiModule.m
(line 155 in the referenced build). The actual problem appears to be in the
close:withObject: method of TiUIiPhoneNavigationGroup.m
.
The following changes to
TiUIiPhoneNavigationGroup.m
resolves the issue:
@@ -117,8 +119,9 @@
NSMutableArray* newControllers = [NSMutableArray arrayWithArray:controller.viewControllers];
BOOL animated = [TiUtils boolValue:@"animated" properties:properties def:(windowController == [newControllers lastObject])];
[newControllers removeObject:windowController];
- [closingProxy autorelease];
- closingProxy = [window retain];
+// [closingProxy autorelease];
+// closingProxy = [window retain];
+ [window close:nil];
[controller setViewControllers:newControllers animated:animated];
}
@@ -152,9 +155,9 @@
}
[self setVisibleProxy:newWindow];
}
- [closingProxy close:nil];
- [closingProxy release];
- closingProxy = nil;
+// [closingProxy close:nil];
+// [closingProxy release];
+// closingProxy = nil;
opening = NO;
[newWindow windowDidOpen];
}
After some additional testing, I was able to avoid the leak by making the following changes to TiUIiPhoneNavigationGroup.m:
I've attached sample code to help reproduce the crash. When using an unmodified 1.8.20111028x CI build, the app generally crashes for me after one or two presses of the "Start Test" button. If TiUIiPhoneNavigationGroup.m is modified as described above, the code runs fine.
Paul Do you know if this has been resolved in 1.8.0.1? Does your test case still exhibit the same issue? Thank you for including the solution to this. In order for us to use any of your code, you will need to sign the CLA. See [Signing the Contributors License Agreement (CLA)](https://wiki.appcelerator.org/display/guides/How+to+Contribute+Code#HowtoContributeCode-SigningtheContributorsLicenseAgreement%28CLA%29) for info. Have you done this, or do we need to organize it? Thanks
Closing due to inactivity. If this issue still exists, please raise a new ticket, including all the information in the [JIRA Ticket Checklist](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist) to ensure that we can escalate it quickly. Read [How to Submit a Bug Report](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report) if you have not read it before, and always start a ticket using the [JIRA Ticket Template](https://wiki.appcelerator.org/display/guides/JIRA+Ticket+Template). Thanks in advance