[TIMOB-24096] iOS: Removing webviews from parent views crashes app
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Not Our Bug |
Resolution Date | 2016-11-04T14:09:52.000+0000 |
Affected Version/s | Release 5.5.1 |
Fix Version/s | n/a |
Components | iOS |
Labels | defect, ios, iphone |
Reporter | Uhlig Mobile |
Assignee | Hans Knöchel |
Created | 2016-10-17T19:03:40.000+0000 |
Updated | 2017-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
File | Date | Size |
---|---|---|
index.js | 2016-10-31T18:10:17.000+0000 | 1364 |
index.xml | 2016-10-31T18:10:17.000+0000 | 46 |
I tried making this a ticket under TIMOB but I couldn't figure out how. Sorry, this is my first time reporting a bug :)
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!
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.
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.
I have updated the sample code. It should work correctly now. Thank you!
Hello, Send the full code index.xml, index.js. Thanks.
I have attached the requested index.js and index.xml files
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
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
andheight : 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 callingremove
- UseTi.UI.FILL
instead of100 %
for a generally improved performance - You should always remove views directly, and not use thechildren[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 errorInvalid 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 asNot our Bug
for now. Follow the above improvements and the app will work again, thx!Closing ticket with reference to the previous comments.