Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25750] iOS: Closing window with webview from within load event crashes app

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 7.0.1, Release 8.0.0
Fix Version/sn/a
Componentsn/a
LabelsengSchedule, ios, webview
ReporterMichiel van Eerd
AssigneeShak Hossain
Created2018-01-02T11:00:25.000+0000
Updated2019-04-23T21:56:12.000+0000

Description

When I close a window with a webview from within the load event the app crashes. I'm not sure this is a bug. A simple workaround is to close the with a timeout of 0 seconds.
$.webView.addEventListener("load", onWebViewLoad);

// This crashes
function onWebViewLoad(e) {
  $.webWindow.close();
}

// This works
function onWebViewLoad(e) {
  setTimeout(function() {
    $.webWindow.close();
  }, 0);
}

Comments

  1. Mostafizur Rahman 2018-01-03

    Hello [~michielve], Tested the issue with the sample code below and unable to reproduce this on on our end using SDK SDK 7.0.1.GA. The project is running without any crash. *Test code:* *index.js*
       $.win.open();
       $.webView.addEventListener("load", onWebViewLoad);
        
       // This crashes
       function onWebViewLoad(e) {
         $.win.close();
       }
        /*
       // This works
       function onWebViewLoad(e) {
         setTimeout(function() {
           $.webWindow.close();
         }, 0);
       }
       */
       
    *index.xml*
       <Alloy>
           <Window id="win" modal="true">
               <WebView id="webView" url="http://www.appcelerator.com" />
           </Window>
       </Alloy>
       
    *Test environment:*
       
       Appcelerator Command-Line Interface, version 7.0.1
       Copyright (c) 2014-2018, Appcelerator, Inc.  All Rights Reserved.
       
       Operating System
         Name                        = Mac OS X
         Version                     = 10.13.1
         Architecture                = 64bit
         # CPUs                      = 4
         Memory                      = 8.0GB
       
       Node.js
         Node.js Version             = 8.9.1
         npm Version                 = 5.5.1
       
       Appcelerator CLI
         Installer                   = 4.2.11
         Core Package                = 7.0.1
       
       Titanium CLI
         CLI Version                 = 5.0.14
         node-appc Version           = 0.2.41
       
       Titanium SDKs
         7.0.1.GA
           Version                   = 7.0.1
       platform=iOS Simulator
       
       
    *Test Result:* *Console logs:*
       [INFO] :   Invoking xcodebuild
       [DEBUG] :  Invoking: DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild build -target jn_Alloy2017 -configuration Debug -scheme jn_Alloy2017 -derivedDataPath /Users/user/Documents/Appcelerator_Studio_Workspace/jn_Alloy2017/build/iphone/DerivedData OBJROOT=/Users/user/Documents/Appcelerator_Studio_Workspace/jn_Alloy2017/build/iphone/build/Intermediates SHARED_PRECOMPS_DIR=/Users/user/Documents/Appcelerator_Studio_Workspace/jn_Alloy2017/build/iphone/build/Intermediates/PrecompiledHeaders SYMROOT=/Users/user/Documents/Appcelerator_Studio_Workspace/jn_Alloy2017/build/iphone/build/Products -destination "platform=iOS Simulator,id=C7002023-D6CC-4E16-AE36-B0CD715809F5,OS=11.0" ONLY_ACTIVE_ARCH=1
       [INFO] :   Finished building the application in 2m 26s 727ms
       
    Can you please try the sample code above and share the logs here?
  2. Hans Knöchel 2018-01-03

    Tested it as well (env: 7.0.1, both kroll- and main-thread) and it works fine:
       var win = Ti.UI.createWindow({
         backgroundColor: 'green',
         title: 'Window 1'
       });
       
       
       var btn = Ti.UI.createButton({
         title: 'Open Window'
       });
       
       btn.addEventListener('click', openWindow);
       
       win.add(btn);
       
       var nav = Ti.UI.iOS.createNavigationWindow({
         window: win
       });
       
       nav.open();
       
       function openWindow() {
         var win2 = Ti.UI.createWindow({
           backgroundColor: 'blue',
           title: 'Window 2'
         });
       
         var webView = Ti.UI.createWebView({
           url: 'http://appcelerator.com'
         });
       
         webView.addEventListener("load", function() {
           win2.close();
         });
         
         win2.add(webView);
         
         nav.openWindow(win2);
       }
       
    I agree with [~shossain], we either need a full trace-log of the crash or something with your scope is incorrect, causing this crash. I've seen those crashes when you have global Ti.App listeners in a sub-scope like event-listeners. Please check your code!
  3. Michiel van Eerd 2018-01-04

    Thank you for your feedback. I created a new empty project without any dependencies with the same result. Immediately closing the window crashes the app, with a setTimeout 0 everything is okay. I see no log in the console after the crash, but in the system.log file is see the following: {noformat} Jan 4 09:02:01 Mac-mini-van-Michiel WebviewTest[5202]: objc[5202]: Class MPExportableArtworkProperties is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/MediaPlayer.framework/MediaPlayer (0x10b9e97d0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/MediaPlaybackCore.framework/MediaPlaybackCore (0x12cccb108). One of the two will be used. Which one is undefined. Jan 4 09:02:02 Mac-mini-van-Michiel com.apple.CoreSimulator.SimDevice.13F4A5B8-3342-4E04-BA4D-8D5506B487FD[5076] (UIKitApplication:nl.michielve.webviewtest[0x8b14][5102][5202]): Service exited due to signal: Segmentation fault: 11 sent by exc handler[0] {noformat} The Alloy project:
       function doClick(e) {
         var win = Alloy.createController("webWindow").getView();
         win.open();
       }
       $.index.open();
       
       <Alloy>
         <Window class="container">
           <Label id="label" onClick="doClick">Hello, World</Label>
         </Window>
       </Alloy>
       
       $.webView.addEventListener("load", function() {
         $.webWindow.close();
       });
       
       <Alloy>
         <Window class="container">
           <WebView id="webView" url="http://appcelerator.com" />
         </Window>
       </Alloy>
       
  4. Hans Knöchel 2018-01-04

    Thanks, we'll check. The logs are system-logs from iOS and unrelated. They started appearing with Xcode 8 (both Titanium and native) and can be pretty misleading. We'll come back to you later.
  5. Sharif AbuDarda 2018-01-04

    Hello [~hknoechel], [~michielve], I was able to reproduce the issue in iOS simulator 11.2. I ran the project with trace log. When I click on the "hello world" I do see the Appcelerator website open and in 2 seconds the app crashes to simulator home screen. No crash log in the console. My environment
       Mac OS High Sierra, 64bit
       Node 8.9.1
       iOS simulator 11.2
       SDK 7.0.1.GA
       
    Thanks.
  6. Alan Hutton 2019-04-22

    Reproducable with : iOS simulator 12.2 Node.js Node.js Version = 8.11.3 npm Version = 6.7.0 Titanium CLI CLI Version = 5.1.1 Titanium SDK SDK Version = 8.0.0.GA

JSON Source