Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4751] Random crash using getElementsByTagName to parse XML

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionCannot Reproduce
Resolution Date2011-08-01T11:54:31.000+0000
Affected Version/sn/a
Fix Version/sSprint 2011-31
ComponentsiOS
Labelsbad_access, callback, xmlparsing
ReporterDavide Bertola
AssigneeBlain Hamon
Created2011-07-20T05:10:22.000+0000
Updated2012-02-09T14:02:43.000+0000

Description

Attachments

FileDateSize
stacktrace.txt2011-07-21T02:50:43.000+00001590

Comments

  1. Davide Bertola 2011-07-22

    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 ();
       
  2. Davide Bertola 2011-07-22

    inside KrollObject, in function ConvertIdTiValue around line 266 we have
       	else if ([obj isKindOfClass:[KrollMethod class]])
       	{
       		KrollContext * ourContext = [(KrollMethod *)obj context];
       		if (context == ourContext)
       		{
       			return [(KrollMethod *)obj jsobject];
       		}
       		return TiObjectMake(jsContext,KrollMethodClassRef,obj);
       	}
       
    disabling the internal IF seems to fix the crash, but don't know why
       	else if ([obj isKindOfClass:[KrollMethod class]])
       	{
       		KrollContext * ourContext = [(KrollMethod *)obj context];
       		if (context == ourContext && 0)
       		{
       			return [(KrollMethod *)obj jsobject];
       		}
       		return TiObjectMake(jsContext,KrollMethodClassRef,obj);
       	}
       
    I hope this helps
  3. Eduardo Gomez 2011-07-27

    Associated HD ticket

    A PRO customer relies on this, http://appc.me/c/APP-414331

    Repro 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();
       
  4. Blain Hamon 2011-08-01

    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.
  5. Thomas Huelbert 2012-02-09

    closing as we are not able to reproduce using master (1.9.0 Feb 9 2012 09:46 rd47ce8a4)

JSON Source