a crash when exiting an overlay scene with a webView (only happens in iOS device testing)

@boscotwcheung, This has not been fixed yet.

I can confirm this crash as well. I have a webview that’s in an overlay scene. I create the webview in willEnterScene and do the following in exitScene:

  1. Stop the webview’s request using stop()
  2. Remove the “urlRequest” event listener
  3. Call removeSelf() on the webview
  4. Set the webview to nil

Even with all of the above, it crashes if I close the webview while it’s loading. Anyone else find a fix? I’m on build 2014.2135.

You should get an event from the webView that lets you know when it’s loaded.  You could disable your back button or whatever you’re doing to trigger the closing of the overlay until you know the webView has loaded. 

What is likely happening is that you’re closing the overlay (and potentially removing it) and the callBack function that triggers when the webView loads ls looking for something that’s no longer in memory and casing your Segment Violation.  This would happen if you have an onComplete on an audio track too. 

Rob

If the app depends on the events to check if it’s loading status or not (in order to disable the back button), I think there are many problems:

(1) It’s a bad user experience. What if the Internet connection is slow? The user has to be waiting for the webView (a blank screen) and cannot do anything, even exiting?

(2) The events from the webView are not that reliable from my experience with it for the last three months. Sometimes there are some event missing and sometimes there are inconsistent patterns. For example, I tried to use events to determine the current link address, but I can only get 90% accuracy because of the inconsistency or missing events. Even after the “loaded” event is added, I still cannot rely on the loaded events to get the current link address for 100% accuracy because the loaded event is missed in some cases. I prefer not to use the loaded event in my case because it has lower than 90% accuracy for me to determine the current link address. 

And if there is some missed event when determining if the webView is loaded, the user is gonna get stuck at this webView forever, terrible user experience.

(3) There are times when I click a link inside a webpage, the page does not show up, and the backward button flag is not set. The webView goes into a weird state. I have implemented a feature to open the current link in Safari, so I try to open the same link in Safari, there is no problem to open that page. So I conclude it’s a problem about the webView. If this happens, another terrible user experience.

I think webView component really needs more attention & more enhancements in its fundamental implementation. This kind of workaround does not (can not) help the webView’s vulnerability.

Hey @Rob,

Thanks for the suggestion, you’re likely right as to what’s happening. However, I agree with @joe528 that it’s bad UX if I have to disable the close button until a page has loaded. Not to mention, in the docs it states:

 There is a known issue on actual iOS devices in which subsequent “loaded” events are not triggered. This is currently being investigated.

Is there anything else that can be tried to close the webview while it’s loading?

@max84 

(1) Have you tried the solution above? (call webView:removeSelf() in destroyScene() instead)

I have no problem to close the webView here. There is no crash even if it’s in loading state.

(2) About the documentation saying subsequent “loaded” events are not triggered. According to Corona, they have fixed this issue. There is subsequent loaded event for iOS devices. However, what I have observed is that in most cases, there are the expected loaded events, but it’s still missing in some case. This has been discussed in another thread, however Corona has not shown they recognize this new problem.

Daily build 2174 seems having fixed this issue?

  • iOS/Mac: Resolving issue when closing/removing WebView from scene casenum:25975, 28771, 27995, 28729

If you have the issue (I can’t reproduce it somehow), maybe you want to verify it… & post some result here… would like to know if everything goes better for webView.

Thanks.

It works for me using daily build 2174

No crashes using Daily Build 2174, yeah and thanks!

@joe528: I tried moving the removeSelf to the destroyScene with the same results.

I still have no fix for this on 2013.2100, and I can confirm that subsequent ‘loaded’ events are not always properly dispatched on iOS devices.

@max84

(1) Do you put removeEventListener() in exitScene() ? 

    It’s weird that you are experiencing this crash. My app is a reader app and relies on the webView a lot. It does not crash that way as you described.

(2) I have not reported this bug about the loaded event, because I think this single issue is not going to get webView anywhere. If you also rely on webView a lot for your apps, I hope you can also join the force to make Corona identify webView’s “whole” problem.

@joe528, I’ve tried putting the removeEventListener damn near everywhere. I’m still able to crash the webview, even if I wait for a loaded event before re-enabling the button. This is a really bad crash that we can’t seem to work around. I’ll post anything else I find, but as of now I’m at a loss. Any other input/suggestions would be greatly appreciated.

@max84 

Do you mean it crashes in Simulator?

I have found the webView would crash in simulator for certain web pages, no matter what.

However, it does not crash in actual devices. Therefore, I ignore this problem for Simulator.

I didn’t report this crash for the Simulator because I hope Corona can spend more time to enhance webView from the ground.

I ended up finding a workaround, but the bug remains.

What’s the workaround? What bug remains?

Do you have the crash in Simulator or/and actual devices?

Thank you very much for this thread. I started trying out the newWebView API (as opposed to showWebPopup which I used to use) and came up with this exact same issue. Segmentation fault: 11 in my console. Crash after 5 consecutive loads, moving in & out of scene etc. I will try the suggested methods to cope. Hope there is a more robust solution along the way. Thanks.

@ksan / @joe528

I ended up working around this by doing the following:

In my button handler for closing the overlay scene, I stop the webview and attempt to remove the event listener:

[lua]

webView:stop()

webView:removeEventListener(‘urlRequest’, listener)

[/lua]

I then have to add an artificial delay to the exit of my overlay:

[lua]

timer.performWithDelay( 200, function()

  storyboard.removeOverlay()

end)

[/lua]

And finally in my exitScene:

[lua]

webView:removeSelf()

webView = nil

[/lua]

I hope that helps anyone else trying to use webViews.

Great guidance. Thank you very much trying it right now. 

@max84

Thanks for the sharing the workaround

But I really don’t like the delay… Although only 200ms, it’s still not a good UI experience. Besides, Corona should fix this.

Do you see the crash in Simulator? Is your workaround applied to Simulator?

By the way, is it stable on the latest dailies for you? My previously working app (using showWebPopup) was acting funny in the later dailies and hence my diving into the new API but now I’m not seeing consistent results here either. Going back to 2100 to see how it works there. So for clarity, can you kindly let me know which build you’re on and whether your experience is rock solid? Thanks

Edit - Took my old code using showWebPopup back to 2100 and it is rock solid once again. Something is not right on later builds but I don’t know how to report this. Anyways its off topic for this thread.