google-ar / WebARonARKit

An experimental app for iOS that lets developers create Augmented Reality (AR) experiences using web technologies.
https://developers.google.com/ar/develop/web/getting-started
Apache License 2.0
771 stars 104 forks source link

undefined is not an object #52

Open erikparr opened 6 years ago

erikparr commented 6 years ago

Hi - Very nice project here. I'm exploring your examples and I keep getting the following error on plane finder example. I am on WebARonARKit, ios 11.2.5 three.js .89, and three.ar.js 1.7 img_0038

judax commented 6 years ago

Thank you for reaching out and pointing this problem out. Are you able to consistently reproduce the issue?

erikparr commented 6 years ago

Yes - consistent every time showPlanes is enabled for THREE.ARDebug. When showPlanes is false the error disappears.

ITJesse commented 6 years ago

I can confirm this error. It happens every new suface be found after reload the page in the WKWebView.

I have a workaround, hope it helps. https://github.com/ITJesse/WebARonARKit/commit/833a90d7679a0375a699700fe330f3ab59e8b966

lincolnfrog commented 6 years ago

Thanks, @ITJesse - I left a comment on your fix. This is a deeper problem as basically we are getting the events out-of-order, which can result in all kinds of badness like recreating deleted planes if we get an update after a delete. The correct fix is to handle the events on the native side where they come in the correct order and then send a batch add/update/remove event to JS along with each frame update so it can't come in out-of-order on the JS side.

lincolnfrog commented 6 years ago

@ITJesse I left another comment - would like to get a band-aid in there but I think the best fix is to change onPlaneUpdated_, where the crash happens, to just ignore the update if the plane doesn't exist. That will prevent us from leaking planes if the update/delete come in reverse order. Do you want to make that fix?

ITJesse commented 6 years ago

I will try it later. Thanks.

ITJesse commented 6 years ago

@lincolnfrog I have done some research these days. And I found that it maybe caused by a "dummy restart" of ARSession. See here.

All of the planes had found is still left in the native side. This will cause the data to be out of sync between native and WKWebkit side after a web page reload happened (maybe out-of-memory, refresh, and so on).

So when we found a plane again, the native will fire a onPlaneUpdate event instead of a onPlaneAdded event which we expect.