Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2795] iOS: UI.iPhone - NavigationGroup.close() crashes with EXC_BAD_ACCESS

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2011-12-28T06:37:32.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterPaul Mietz Egli
AssigneePaul Dowsett
Created2011-11-06T16:07:40.000+0000
Updated2016-03-08T07:47:43.000+0000

Description

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];
 }

Attachments

FileDateSize
app.js2011-11-07T08:03:32.000+0000995

Comments

  1. Paul Mietz Egli 2011-11-06

    After some additional testing, I was able to avoid the leak by making the following changes to TiUIiPhoneNavigationGroup.m:
       @@ -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];
        }
       
  2. Paul Mietz Egli 2011-11-07

    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.
  3. Paul Dowsett 2011-12-28

    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
  4. Paul Dowsett 2012-02-17

    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

JSON Source