[TIMOB-4896] iOS: Application crash when opening a window and firing an event immediately which in turn closes the window
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-02-01T15:59:37.000+0000 |
Affected Version/s | Release 1.7.1, Release 1.7.2 |
Fix Version/s | Sprint 2012-02, Release 2.0.0, Release 1.8.1 |
Components | iOS |
Labels | module_window, parity, qe-testadded |
Reporter | Matthew O'Riordan |
Assignee | Stephen Tramer |
Created | 2011-07-20T11:04:54.000+0000 |
Updated | 2012-03-04T22:18:02.000+0000 |
Description
I have discovered that when opening a window quickly, firing an event, and closing it again, my application will sometimes completely crash. I've tested this when the window that is opening another window is part of a Tab group, and that makes the error occur more consistently, so the code I have provided is an example using a TabGroup.
Ti.UI.setBackgroundColor('#000');
var tabGroup = Ti.UI.createTabGroup();
var win2 = Ti.UI.createWindow({
title:'valueForUndefinedKey',
backgroundColor:'red',
url:'bugs/window_crash.js'
});
var tab2 = Ti.UI.createTab({
title:'undefinedKey',
window:win2
});
tabGroup.addTab(tab2);
tabGroup.open();
var win;
var button = Titanium.UI.createButton({
title: 'Show Window',
width: 300,
height: 40
});
button.addEventListener('click', function() {
win = Titanium.UI.createWindow({
fullscreen: true,
backgroundColor: '#666',
url: 'window_crash_subwindow.js'
});
win.addEventListener('ready', function() {
// win.close causes an error only if called immediately after window is created
win.close();
});
win.open();
});
var label = Titanium.UI.createLabel({
text: 'Press that button a few times and watch it crash',
color: '#000',
height: 'auto',
bottom: 40
});
Titanium.UI.currentWindow.add(label);
Titanium.UI.currentWindow.add(button);
Ti.UI.currentWindow.fireEvent('ready');
Here is the complete log of the application.
[INFO] One moment, building ...
[DEBUG] Detecting modules in /Users/matthew/Projects/Titanium Studio Workspace/titanium_bugs/modules
[DEBUG] Detecting modules in /Library/Application Support/Titanium/modules
[INFO] Titanium SDK version: 1.7.2
[INFO] iPhone Device family: universal
[INFO] iPhone SDK version: 4.3
[INFO] iPhone simulated device: iphone
[DEBUG] executing command: /usr/bin/killall iPhone Simulator
[DEBUG] No matching processes belonging to you were found
[DEBUG] finding old log files
[DEBUG] executing command: mdfind -onlyin /Users/matthew/Library/Application Support/iPhone Simulator/4.3 -name 70553166-5807-402d-bfcb-8243509b1723.log
[INFO] Launching application in Simulator
[INFO] Launched application in Simulator (11.64 seconds)
[DEBUG] executing command: xcodebuild -version
[DEBUG] Xcode 4.1
[DEBUG] Build version 4B110
[INFO] Found 4.3.2 patch installed
[INFO] Application started
[DEBUG] reading stylesheet from: /Users/matthew/Library/Application Support/iPhone Simulator/4.3.2/Applications/5A13E843-A139-4466-985E-EDC6FB65F270/titanium_bugs.app/stylesheet.plist
[INFO] titanium_bugs/1.0 (1.7.2.97c3689)
[DEBUG] App Spec: <DTiPhoneSimulatorApplicationSpecifier 0x100125cf0> specified by path /Users/matthew/Projects/Titanium Studio Workspace/titanium_bugs/build/iphone/build/Debug-iphonesimulator/titanium_bugs.app
[DEBUG] SDK Root: <DTiPhoneSimulatorSystemRoot 0x1001243b0> path=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk version=4.3 name=Simulator - iOS 4.3
[DEBUG] using device family iphone
[DEBUG] Session started
[DEBUG] Session did end with error Error Domain=DTiPhoneSimulatorErrorDomain Code=1 "The simulated application quit." UserInfo=0x100303560 {NSLocalizedDescription=The simulated application quit., DTiPhoneSimulatorUnderlyingErrorCodeKey=-1}
[INFO] Application has exited from Simulator
Further to this, I have discovered that if this.window.close() is called very soon after the window is created, this behaviour typically happens. I found a workaround by waiting a split second and then calling close i.e. setTimeout(function() { window.close(); }, 1); Unfortunately I'm now experiencing this issue on a fireEvent call as well, even if I use the setTimeout workaround from above. See http://developer.appcelerator.com/question/122908/uiwindow-0x6b1be40-valueforundefinedkey-this-class-is-not-key-value-coding-compliant-for-the-key-close#comment-91775 for a complete list of what is happening. BTW. I've tried this with 1.7.2 as well and the problem persists.
Matthew Please would you read the [Creating Good Use-cases](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-CreatingGoodUsecases) and amend your ticket accordingly. Please use a sequential list of Titanium API calls in favor of custom functions. Please use the wiki markup provided (edit your ticket, rather than add another comment). State the build date and hash of the Titanium SDK you have tested. State your mobile platform version, in the environment field. Once this is corrected, we can progress this ticket. Many thanks
Please observe the [Jira Ticket Checklist](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-Summary%3AJiraTicketChecklist) when raising tickets. Thanks
Hi Paul Sorry, was not aware of the protocol, so here goes: Environment: Titanium SDK version: 1.7.2 (I don't see where build date / hash comes from, I am using the version that was automatically installed by Titanium Studio when 1.7.2 was released a week or so ago). I see an [INFO] log saying something about 1.7.2.97c3689, is that what you need? Platform & version: iOS 4.3, OSX 10.7 (Lion) Device Details: iOS simulator and iOS device Host Operating System: OSX 10.7 Titanium Studio version: Titanium Studio, build: 1.0.2.201107130739 Code for app.js
Code for value_for_undefined_key_subwindow.js
Strangely with this code example I have provided I have been unable to replicate the reporting of the valueForUndefinedKey exception that was thrown, however after you open the window a few times it will consistently crash with only the following message:
I hope that will suffice.
As I'm sure you will raise this as "not working code" too, please rename app.js to bug.js and use the following code for app.js.
Matthew Would you kindly correct the body of the ticket, and other fields, rather than add a comment. It makes it easier for the core devs. Thanks
Fine Paul, I will update the initial post. Thanks for being so unhelpful and making the process of reporting a bug in your product so difficult, time consuming and painful.
Oops, I forgot to say, if the valueForUndefinedKey error is no longer reproducable, then would you also change the title to reflect the new issue? Thanks
Hopefully that is better now then.
Matthew Window creation in bugs/window_crash.js should be contained within the button event, so that it is destroyed correctly, otherwise your code will be unstable. Would you please try the following corrected code, and report back with the log if it still crashes? Thanks
Hi Paul Firstly, I am not sure I am clear on why I should have to recreate Windows every time. Surely the open() and close() methods are there so that you can reuse the resource? If you take a look at the documentation at [http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object](http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object) it says "Unlike Views, Windows can be opened and closed and can have special display properties such as fullscreen or modal." Either way, I tried your code, and I get the same problem. Here is the actual code I used for bugs/window_crash.js. All the other code remains exactly the same.
Behavior has changed where this no longer leads to a crash, but instead just doesn't fire the close() properly (the window isn't "opened" when the close() call occurs). We probably need a check to abort opening a window if close() is called during the process, or to reschedule it. Build 1.9.0.c3fc109
Fixed by PR https://github.com/appcelerator/titanium_mobile/pull/1212
Tested with 1.9.0.v20120119134634 with iphone 3gs (4.3) - fixed