[AC-5979] iOS 12 - TabGroup.activeTab.openWindow opens window blank
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Needs more info |
Resolution Date | 2018-12-02T09:50:41.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | ios |
Reporter | David Bankier |
Assignee | Shak Hossain |
Created | 2018-10-17T06:32:52.000+0000 |
Updated | 2018-12-02T09:50:41.000+0000 |
Description
When using
TabGroup.activeTab.openWindow
the windows that opens sometimes does not appear. The sample code below generally replicates the problem the first time the function is called, without the (code heavy) window, instead a black screen appears.
'use strict';
function createWindow() {
var win = Ti.UI.createWindow();
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function rand() {
return Math.floor(Math.random() * 10);
}
function createRow(i) {
var r = Ti.UI.createTableViewRow({
backgroundColor: getRandomColor(),
height: 50
});
var l = Ti.UI.createLabel({
text: 'Loading...' + i,
left: 0
});
r.add(l);
r.go = function() {
setTimeout(function() {
l.text = 'Loaded ' + i;
//r.backgroundColor = getRandomColor();
l.animate({
duration: 500,
autoreverse: true,
repeat: 5,
left: 250
});
}, rand() * 200);
};
return r;
}
var rows = [];
for (var i = 0; i < 10000; i++) {
rows.push(createRow(i));
}
function createSection() {
var s = Ti.UI.createTableViewSection();
rows.forEach(r => {
s.add(r);
setTimeout(function() {
r.go();
}, 0);
});
return s;
}
var table = Ti.UI.createTableView({
data: [createSection()]
});
win.add(table);
return win;
}
function createTabGroup() {
var tabs = ['blue', 'red', 'green', 'yellow'].map(function(c) {
var win = Ti.UI.createWindow({
backgroundColor: c,
title: c
});
win.add(Ti.UI.createLabel({ text: 'I am a' + c + ' window.' }));
win.addEventListener('click', openTab);
var tab = Ti.UI.createTab({
window: win,
title: c
});
return tab;
});
var tabGroup = Ti.UI.createTabGroup({
tabs: tabs
});
return tabGroup;
}
var tabGroup = createTabGroup();
let win;
function openTab() {
//if (win) { tabGroup.activeTab.close(win); }
win = createWindow();
tabGroup.activeTab.open(win);
}
setInterval(openTab, 3000);
tabGroup.open();
This can be replicated in the simulator and with or without jscore.
So i guess this is just an example to replicate the problem, right? Anyhow, the excessive use of
setTimeout(func, 0)
seems to be an issue. What happens under the hood is that a new thread will be created so the timer does not block on the main thread until it is triggered. You callsetTimeout
10000 times every three seconds in this example. All these calls pile up until eventually it crashes somewhere in the internal thread handling of the kernel because the device cannot process all these threads fast enough. I had ~1500 threads active at the time of the crashes which is just way too much for the OS to handle. Removing thesetTimeout
removed the main issue for me and more windows opened after some time. However, i guess you were doing this to properly schedule theanimate
calls after adding a new row?This is just example code. The issue happens even without the interval/timeout. I am using it to save clicks and taps as it is hard to replicate. I have large apps where tapping on a menu item opens a window in this manner (without a timeout) and sometimes appears blank.
Can you provide a sample project? With the example code the app is crashing due to the massive amount of threads. On sim it's going black for a short time but then it also crashes. Are you seeing crashes too? Do you have crash reports you can share? Or will it just open a black window but keeps running?
I am experiencing this same issue on my apps as well. Not using any setTimeout code. Just randomly get a blank window instead of my window with tableview. The app does not crash for me, just blank window. It appears to happen more frequently on older devices. It is pretty common with iPhone 6 devices.
Hello [~kstorm001], Can you provide a standalone sample code that generates the issue for the older iOS device? We will lest on our end. Thanks.