Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24096] iOS: Removing webviews from parent views crashes app

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionNot Our Bug
Resolution Date2016-11-04T14:09:52.000+0000
Affected Version/sRelease 5.5.1
Fix Version/sn/a
ComponentsiOS
Labelsdefect, ios, iphone
ReporterUhlig Mobile
AssigneeHans Knöchel
Created2016-10-17T19:03:40.000+0000
Updated2017-03-24T18:57:01.000+0000

Description

When navigating from a view back to another view, if you try and remove a webview from the view you are leaving, the app freezes and then eventually crashes. Test Case:
index.js

var testView = Ti.UI.createView({
	layout: 'vertical',
	backgroundColor: '#FFF'
});
var button1 = Ti.UI.createButton({
	height: 50,
	width: 100,
	backgroundColor: '#00FF00',
	color: '#FFF',
	top: 50, 
	title: 'Get View'
});

var firstView = Ti.UI.createView({
	backgroundColor: '#CFCFCF'
});

var button2 = Ti.UI.createButton({
	backgroundColor: '#000',
	color: '#FFF',
	height: 50,
	width: 100,
	title: 'Get WebView'
});

var secondView = Ti.UI.createView();

var button3 = Ti.UI.createButton({
	backgroundColor: '#0000FF',
	color: '#FFF',
	height: 50,
	width: 100,
	top: 60,
	title: 'Go Back'
});

button3.addEventListener( 'click', function( e ) {
	var items = firstView.children;
	
	for( var i = 0; i<=items.length; i++ ){
		firstView.remove( items[ i ] );
		items[ i ] = null;
	}
});

var webView = Ti.UI.createWebView({
	height : Titanium.UI.SIZE,
	width : '100%',
	top: 20,
	contentHeight : Ti.UI.SIZE,
	bottom : 0,
	font : Alloy.CFG.FONT_14,
	color : '#666',
	ignoreSslError : true,
	html: '<b>This is only a test. Do not be alarmed.</b>'
});

secondView.add(webView);
secondView.add(button3);

button2.addEventListener( 'click', function( e ) {
	firstView.add(secondView);
});

firstView.add( button2 );

button1.addEventListener( 'click', function( e ) {
	testView.add( firstView );
});
testView.add( button1 );

$.index.add( testView );

$.index.open();
Process to create bug: 1) Click 'Get View' button 2) Click 'Get WebView' button 3) Click 'Go Back' button 4) Now, click 'Get View' button again and app will freeze and then eventually crash. I cannot reproduce this issue on Android, only iOS.

Attachments

FileDateSize
index.js2016-10-31T18:10:17.000+00001364
index.xml2016-10-31T18:10:17.000+000046

Comments

  1. Uhlig Mobile 2016-10-17

    I tried making this a ticket under TIMOB but I couldn't figure out how. Sorry, this is my first time reporting a bug :)
  2. Hans Knöchel 2016-10-18

    Please provide the test-case in a single JS file so it can be debugged better. But there are some problems with your code as well, for example you are firing the "open" event manually. This is fired by the system. You are also trying to use an open event to a view, but they are only used for window instances. We can validate the issue after the single-file test-case is available, thx!
  3. Uhlig Mobile 2016-10-20

    Hello Hans Knoechel, I have put all the code into one JS file so you should be able to debug it now. I understand that navigating through views is the wrong approach but this is the way the app was built back when we started using Titanium on 3.1.4, and it just now stopped working on 5.5.1.GA. Let me know what you find out.
  4. Sharif AbuDarda 2016-10-24

    Hello, You haven't provide a full sample code. Please provide a full sample code that regenerated the issue. For example, In here the code you provided "testView" is not defined. Thanks.
  5. Uhlig Mobile 2016-10-24

    I have updated the sample code. It should work correctly now. Thank you!
  6. Sharif AbuDarda 2016-10-28

    Hello, Send the full code index.xml, index.js. Thanks.
  7. Uhlig Mobile 2016-10-31

    I have attached the requested index.js and index.xml files
  8. Sharif AbuDarda 2016-11-03

    Hello, I can reproduce the issue with your sample code. For me the app hangs when removing webview. The issue is reproducible with SDK 5.5.1.GA. perating System Name = Mac OS X Version = 10.11.6 Architecture = 64bit # CPUs = 4 Memory = 8589934592 Node.js Node.js Version = 4.2.2 npm Version = 2.14.7 Titanium CLI CLI Version = 5.0.9 Titanium SDK SDK Version = 5.5.1.GA Target Platform = iphone
  9. Hans Knöchel 2016-11-04

    I am able to reproduce your test-case, but: - You use a lot of incorrect properties that are not even supported by the webview or have no effect, e.g. contentHeight and height : Titanium.UI.SIZE (webviews always fill) - The crash is caused by manually nulling the children (items[ i ] = null; by causing an infinite loop; the children are deallocated automatically when calling remove - Use Ti.UI.FILL instead of 100 % for a generally improved performance - You should always remove views directly, and not use the children[i] property. This is recommended because removing single children will also update the internal index structure of the children everytime you call it. By looping through them, you will have null-values that will be catched by the core, but an error Invalid type passed to function. expected: TiViewProxy, was: NSNull -[TiViewProxy remove:] (TiViewProxy.m:330) will be called as a consequence As a result, I will resolve this issue as Not our Bug for now. Follow the above improvements and the app will work again, thx!
  10. Lee Morris 2017-03-24

    Closing ticket with reference to the previous comments.

JSON Source