[TIMOB-4610] iOS: app crashes when processing xml
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-07-12T07:52:15.000+0000 |
Affected Version/s | Release 1.7.1 |
Fix Version/s | Sprint 2011-27, Release 1.7.2, Release 1.8.0 |
Components | iOS |
Labels | regression |
Reporter | Jon Alter |
Assignee | Blain Hamon |
Created | 2011-07-06T17:23:04.000+0000 |
Updated | 2014-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-495393Attachments
File | Date | Size |
---|---|---|
TimeStamp_example2.kml | 2011-07-06T17:23:04.000+0000 | 2645 |
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:
This took longer than I hoped. Very pesky trickery. Pull request is pending.
D'oh. I keep forgetting. Having a pull request isn't 'fixed'. We need a 'pull request' status.
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.
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
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.