Skip to content

Fix race that dropped every successful cloud anchor upload callback - #37

Open
Brian-Simmons1 wants to merge 1 commit into
hlefe:mainfrom
Brian-Simmons1:fix/upload-anchor-callback-race
Open

Fix race that dropped every successful cloud anchor upload callback#37
Brian-Simmons1 wants to merge 1 commit into
hlefe:mainfrom
Brian-Simmons1:fix/upload-anchor-callback-race

Conversation

@Brian-Simmons1

Copy link
Copy Markdown

ARAnchorManager.uploadAnchor adds the anchor to pendingAnchors only after awaiting the platform call:

final response = await _channel.invokeMethod<bool>('uploadAnchor', anchor.toJson());
pendingAnchors.add(anchor);

But the native side invokes onCloudAnchorUploaded before resolving that method call (the Kotlin handler fires the callback and then calls result.success). So when the success callback runs, pendingAnchors.where((e) => e.name == name).first always throws Bad state: No element — the anchor hosts successfully in the cloud (log shows UPLOADED ANCHOR WITH ID: ua-…), but onAnchorUploaded never fires and the caller never receives the cloud anchor ID.

This PR registers the anchor as pending before the platform call and removes it again on failure, so the callback finds it and the API works as documented.

Verified on device: before — every successful host logged Error caught: Bad state: No element; after — onAnchorUploaded fires with the populated cloudanchorid.

Found and fixed in production while building VEEOP, an AR social location platform (github.com/VEEOP-app).

uploadAnchor added the anchor to pendingAnchors only after awaiting
the platform call, but the native side invokes onCloudAnchorUploaded
before resolving that call. The success handler therefore always hit
an empty pendingAnchors list and threw "Bad state: No element": the
anchor was hosted to the cloud, but onAnchorUploaded never fired and
the caller never learned the cloud anchor ID.

Register the anchor as pending before the call, and unregister it on
failure.

Found and fixed in production while building VEEOP (https://veeop.com),
an AR social location platform - https://github.com/VEEOP-app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant