[TIMOB-4751] Random crash using getElementsByTagName to parse XML
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Critical |
| Status | Closed |
| Resolution | Cannot Reproduce |
| Resolution Date | 2011-08-01T11:54:31.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Sprint 2011-31 |
| Components | iOS |
| Labels | bad_access, callback, xmlparsing |
| Reporter | Davide Bertola |
| Assignee | Blain Hamon |
| Created | 2011-07-20T05:10:22.000+0000 |
| Updated | 2012-02-09T14:02:43.000+0000 |
Description
Attachments
| File | Date | Size |
|---|---|---|
| stacktrace.txt | 2011-07-21T02:50:43.000+0000 | 1590 |
I don't know if it's useful but we discovered that we can workaround the crash rewriting the code like this
Titanium.UI.setBackgroundColor('#000'); var app = {}; var win = Ti.UI.createWindow({ title: "Nope" }); var test = Ti.XML.parseString ("<stops><lat>ciao</lat></stops>"); var result = []; function crashIt () { for (var i=0; i<1000; i++) { setTimeout (function () { var foo = test.getElementsByTagName ("lat").item (0).text; result.push (i + " - " + foo); }, 1); } } crashIt (); //Ti.API.debug (result); win.open ();inside KrollObject, in function ConvertIdTiValue around line 266 we have
disabling the internal IF seems to fix the crash, but don't know whyelse if ([obj isKindOfClass:[KrollMethod class]]) { KrollContext * ourContext = [(KrollMethod *)obj context]; if (context == ourContext) { return [(KrollMethod *)obj jsobject]; } return TiObjectMake(jsContext,KrollMethodClassRef,obj); }I hope this helpselse if ([obj isKindOfClass:[KrollMethod class]]) { KrollContext * ourContext = [(KrollMethod *)obj context]; if (context == ourContext && 0) { return [(KrollMethod *)obj jsobject]; } return TiObjectMake(jsContext,KrollMethodClassRef,obj); }Associated HD ticket
A PRO customer relies on this, http://appc.me/c/APP-414331Repro sequence
Once this snippet code starts working and parsing XML data, occasionally app crashes.var xhr = Ti.Network.createHTTPClient(); xhr.open("GET","http://v2.0.news.tmg.s3.amazonaws.com/feeds/news.xml"); xhr.onload = function() { try { var doc = this.responseXML.documentElement; var items = doc.getElementsByTagName("item"); var x = 0; var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue; for (var c=0, l=items.length;c<l;c++) { var item = items.item(c); var elemTitle = item.getElementsByTagName("title").item(0).text; Ti.API.info('-> '+elemTitle); var elemUrl = item.getElementsByTagName("link").item(0).text; Ti.API.info('-> '+elemUrl); //Get and format the date var origDate = item.getElementsByTagName("pubDate").item(0).text; var date_arr = origDate.split(" "); var elemDate = date_arr[2]+" "+date_arr[1]+", "+date_arr[3]; //Push to the array articlesData.push({ title:elemTitle, url:elemUrl, date:elemDate }); } Ti.App.Properties.setList('articlesProp', articlesData); } catch(E) { alert(E); } }; xhr.send();As of Aug 1, could not crash on device or simulator. Given the crash log given, it's highly likely that this was fixed by the new TiJSCore update that happened recently.
closing as we are not able to reproduce using master (1.9.0 Feb 9 2012 09:46 rd47ce8a4)