Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26164] iOS: TableView + run-on-main-thread - insertRowAfter directly after updateRow causes error / race crash

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-08-24T17:23:49.000+0000
Affected Version/sRelease 7.1.1, Release 7.2.0
Fix Version/sRelease 7.5.0
ComponentsiOS
Labelsalloy, run-on-main-thread, tableview, tableviewrow, titanium
ReporterDavid van de Meer
AssigneeVijay Singh
Created2018-06-28T07:21:11.000+0000
Updated2018-08-24T17:23:57.000+0000

Description

When enabling
<property name="run-on-main-thread" type="bool">true</property>
and using TableView, if one runs insertRowAfter directly after updateRow the app will throw the error below or cause race crash with no error. Error:
[ERROR] Script Error {
[ERROR]     column = 27;
[ERROR]     line = 90;
[ERROR]     message = "Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (20) must be equal to the number of rows contained in that section before the update (20), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).";
Steps to reproduce: 1. Create new alloy project 2. In your index.js add the code below 3. Build to ios simlulator 5. Click on "Update + Add" button 7. Remove run-on-main-thread from tiapp.xml and build and see that everything works fine. PS....when adding the setTimeout you will see that it works
var rowData = [];

for (var i=0; i<20; i++){

	var row = Ti.UI.createTableViewRow({
	    height: "50dp",
	    width:	Ti.UI.FILL,
	    title: "row" + i,
	});	

	rowData.push(row);

};

var tableView = Ti.UI.createTableView({
  	data:rowData,
  	bottom: 50,
});

$.index.add(tableView);

var button = Titanium.UI.createButton({
	title: 'Update + Add',
	bottom: 10,
	height: 50,
});

button.addEventListener('click',function(){
		
	var updatedRow = Ti.UI.createTableViewRow({
	    height: "50dp",
	    width:	Ti.UI.FILL,
	    title: "updatedRow",
	});
	tableView.updateRow(0,updatedRow);
		
	//setTimeout(function(){ // uncomment to see it working with a delay
	var newRow = Ti.UI.createTableViewRow({
	    height: '50dp',
	    width:	Ti.UI.FILL,
	    title: "newRow",
	});
	tableView.insertRowAfter(0,newRow);
	//}, 500);
});

$.index.add(button);
	  
$.index.open();

Comments

  1. Vijay Singh 2018-06-28

    Test Case -
       var win = Ti.UI.createWindow({
       	backgroundColor: 'white'
       });
       var rowData = [];
        
       for (var i=0; i<20; i++){
        
       	var row = Ti.UI.createTableViewRow({
       	    height: "50dp",
       	    width:	Ti.UI.FILL,
       	    title: "row" + i,
       	});	
        
       	rowData.push(row);
        
       };
        
       var tableView = Ti.UI.createTableView({
         	data:rowData,
         	bottom: 50,
       });
        
       win.add(tableView);
        
       var button = Titanium.UI.createButton({
       	title: 'Update + Add',
       	bottom: 10,
       	height: 50,
       });
        
       button.addEventListener('click',function(){
       		
       	var updatedRow = Ti.UI.createTableViewRow({
       	    height: "50dp",
       	    width:	Ti.UI.FILL,
       	    title: "updatedRow",
       	});
       	tableView.updateRow(0,updatedRow);
       		
       	//setTimeout(function(){ // uncomment to see it working with a delay
       	var newRow = Ti.UI.createTableViewRow({
       	    height: '50dp',
       	    width:	Ti.UI.FILL,
       	    title: "newRow",
       	});
       	tableView.insertRowAfter(0,newRow);
       	//}, 500);
       });
        
       win.add(button);
       	  
       win.open();
       
  2. Vijay Singh 2018-06-28

    PR : https://github.com/appcelerator/titanium_mobile/pull/10140
  3. David van de Meer 2018-06-29

    Confirmed working on my patched SDK
  4. Samir Mohammed 2018-07-18

    *Closing ticket*, Verified fix in SDK Version: 7.4.0.v20180717131401 *FR Passed (Test Steps):*

    Created a titanium Application

    Added the following code above in to the app.js

    Ran the program

    Pressed "Update + Add"

    Application no longer crashes un like in 7.2.0.GA

    *Test Environment*
       APPC Studio: 5.0.0.201712081732
       APPC CLI: 7.0.4
       iPhone 6 simulator (11.2)
       Operating System Name: Mac OS High Sierra
       Operating System Version: 10.13
       Node.js Version: 8.9.1
       Xcode 9.2
       

JSON Source