Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4610] iOS: app crashes when processing xml

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2011-07-12T07:52:15.000+0000
Affected Version/sRelease 1.7.1
Fix Version/sSprint 2011-27, Release 1.7.2, Release 1.8.0
ComponentsiOS
Labelsregression
ReporterJon Alter
AssigneeBlain Hamon
Created2011-07-06T17:23:04.000+0000
Updated2014-06-19T12:46:13.000+0000

Description

App crashes when processing xml, usually at about 3 loops in. This code crashes when you run it with 1.7.1 and works with 1.6.1. The customer has written the code this way so that they can have a delay between loops. If you remove the 'setTimeout' or 'getElementsByTagName' it will process the whole file without issues. No error in the console when it crashes. I have attached an xml file that you can use for testing if the one in the url doesn't exist. Step 1: run the code below Step 2: click the 'test' button Step 3: in the console you will see about 3 loops output Step 4: notice the app crash
var win = Titanium.UI.createWindow();
win.open();

var ta = Ti.UI.createButton({
	top: 50,
	width: 200,
	height: 30,
	scrollable:false,
	title: "test"
});
win.add(ta);
ta.addEventListener('click', function(e) {
	var xmlPlacemarks;
	var ptr = 0;

	function getNextCoordinate() {
		if ( ptr<xmlPlacemarks.length ) {
			var xmlPlacemark = xmlPlacemarks.item(ptr);
			Ti.API.info(xmlPlacemark);
			if ( xmlPlacemark ) {
				var xmlCoordinates = xmlPlacemark.getElementsByTagName("TimeStamp");
				Ti.API.info("Element Number: " + ptr);
			}
			ptr++;
			Ti.API.info(ptr);
			setTimeout( getNextCoordinate, 1000);
			// getNextCoordinate();
		}
	}

	var xhr = Ti.Network.createHTTPClient();
	xhr.open("GET", "http://code.google.com/intl/nl-NL/apis/kml/documentation/TimeStamp_example.kml");
	// xhr.open("GET", "http://localhost/~jalter/test/TimeStamp_example2.kml");
	xhr.onload = function() {
		xmlPlacemarks = this.responseXML.getElementsByTagName("Placemark");
		Ti.API.info("Simulator found " + xmlPlacemarks.length + " placemarks");
		getNextCoordinate();
	};
	xhr.send();
});

Associated Helpdesk Ticket

http://appc.me/c/APP-495393

Attachments

FileDateSize
TimeStamp_example2.kml2011-07-06T17:23:04.000+00002645

Comments

  1. Blain Hamon 2011-07-07

    Turns out this is because we accidentally give full ownership of the underlying XML data to the document proxy. When it gets garbage collected, it pulls the rug out from under nodes and the like. As a workaround, do the following:
       ta.addEventListener('click', function(e) {
       	var xmlPlacemarks;
       	var xmlDocument;
       	var ptr = 0;
       
       	function getNextCoordinate() {
       		if ( ptr<xmlPlacemarks.length ) {
       			var xmlPlacemark = xmlPlacemarks.item(ptr);
       			Ti.API.info(xmlPlacemark);
       			if ( xmlPlacemark ) {
       				var xmlCoordinates = xmlPlacemark.getElementsByTagName("TimeStamp");
       				Ti.API.info("Element Number: " + ptr);
       			}
       			ptr++;
       			Ti.API.info(ptr);
       			setTimeout( getNextCoordinate, 1000);
       			// getNextCoordinate();
       		}
       	}
       
       	var xhr = Ti.Network.createHTTPClient();
       	xhr.open("GET", "http://code.google.com/intl/nl-NL/apis/kml/documentation/TimeStamp_example.kml");
       	// xhr.open("GET", "http://localhost/~jalter/test/TimeStamp_example2.kml");
       	xhr.onload = function() {
       		xmlDocument = this.responseXML;
       		xmlPlacemarks = xmlDocument.getElementsByTagName("Placemark");
       		Ti.API.info("Simulator found " + xmlPlacemarks.length + " placemarks");
       		getNextCoordinate();
       	};
       	xhr.send();
       });
       
  2. Blain Hamon 2011-07-08

    This took longer than I hoped. Very pesky trickery. Pull request is pending.
  3. Blain Hamon 2011-07-11

    D'oh. I keep forgetting. Having a pull request isn't 'fixed'. We need a 'pull request' status.
  4. Don Thorp 2011-07-12

    Cleaning up issues. Pull request https://github.com/appcelerator/titanium_mobile/pull/210 shows acceptance from QE. Review but no confirmation of acceptance from Dev. Code has already been committed on master and 1_7_X.
  5. Eric Merriman 2011-07-15

    Verified fixed with Titanium Studio build: 1.0.2.201107130739 and SDKs 1.7.2.v20110715075838 r578ee26d and 1.8.0.v2011071507545 rb1ede95e on iPad (3.2.2), iPhone 4 (4.3.3) and iPhone 3G (4.0.2). Closing
  6. Ben S. 2011-08-28

    Will this fix be included in 1.7.3? Cause I'm experiencing this bug in 1.7.2. With 1.8.0 continuous build my app doesn't crash at all, but with 1.7.2 I have irregular crashes in my xml-heavy app.

JSON Source