google-ar / arcore-ios-sdk

ARCore SDK for iOS
https://developers.google.com/ar/
Apache License 2.0
280 stars 80 forks source link

Wrong transforms returned from GARFrame.anchors #102

Open ertembiyik opened 4 months ago

ertembiyik commented 4 months ago

About 3 days ago I started to notice that transforms returned from GARFrame.anchors were wrong. The nodes were either not in the desired spot nor not showing at all. The issue can be reproduced with the sample app from this repository. The issue only takes place when restoring the session, for example adding saved anchors.

I'm using ARCore 1.42 on iPhone 14 Pro, i also reproduced the issue with iPhon 12 too

ertembiyik commented 4 months ago

Seems like all transforms are getting the translations equal to the device's translation at the beginning of the ar session

15kingben commented 4 months ago

Hi Ertem, can you clarify the steps to reproduce this issue? I am not able to reproduce this on the GeospatialExample app. Note that the GeospatialExample does not save geospatial anchors on streetscape geometry. Are the sample app's terrain and rooftop anchors affected as well?

Can you additionally check what values are read from the user defaults to ensure that is not an issue https://github.com/google-ar/arcore-ios-sdk/blob/master/Examples/GeospatialExample/GeospatialExample/ViewController.m#L540

ertembiyik commented 4 months ago

Hi Ben, I was able to properly add saved terrain anchor from example app, but unfortunately the WGS84 anchors didn't load (my app uses them too). I don't use any streetscape geometry inside my app nor in the example one

15kingben commented 4 months ago

When you click the "SHOW GEOMETRY" switch on the sample app, do you see different behavior? When that switch is enabled, the sample app creates anchors on the streetscape geometry which are not saved between sessions, however if you place them on the terrain they may appear the same as normal anchors. When that switch is disabled, anchors are placed on ARKit planes instead, and can be saved.

ertembiyik commented 4 months ago

When I add and then load WGS84 anchors the "SHOW GEOMETRY" switch is in off state, but the saved anchors are not appearing in the scene

ertembiyik commented 4 months ago

Hi @15kingben have you managed to reproduce the issue? Saved WGS84 still don't load in any circumstances

15kingben commented 4 months ago

I am now able to reproduce the issue, sorry for the misunderstanding. I am taking a look now

15kingben commented 4 months ago

Hi Ertem, it seems like an issue with https://github.com/google-ar/arcore-ios-sdk/blob/master/Examples/GeospatialExample/GeospatialExample/ViewController.m#L667 where the nodes are removed when they are added because the current garFrame does not yet have the new anchors. The terrain and Rooftop anchors are async so take at least one frame to resolve. I'm not sure if this was always the case, perhaps SceneKit changed the timing/threading of certain things. It's a race condition regardless. I'll add a fix for this in the next release.

ertembiyik commented 4 months ago

Thanks for your elaboration on that one! To help you more, I wanted to mention that I'm able to reproduce the issue with RealityKit too and it seems to me like the transforms returned from GARFrame's anchors are invalid even after the first frame was processed. They won't update to the correct ones even after some time passes. So I think the issue is somewhere in the sdk itself or more likely in the api response, because I was able to reproduce the same behavior on ARCore 1.41

ertembiyik commented 4 months ago

Hi @15kingben Can you please share the approximate date of the next release? This issue is fatal for apps using WGS84 anchors

Thanks

15kingben commented 4 months ago

The only fix would be in the sample app, note that GARFrames and GARAnchors are immutable, so they will never be updated over time. Rather, you need to get the latest snapshot from garFrame.anchors and update any anchors accordingly.