This repository was archived by the owner on Oct 10, 2026. It is now read-only.
Repository navigation
feat(ar): upgrade companion from procedural spheres to imported Lira USDZ mesh + walking animation #242
Closed
Closed
feat(ar): upgrade companion from procedural spheres to imported Lira USDZ mesh + walking animation #242
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,8 +48,10 @@ final class CanonicalARSessionRuntime { | |
| self.arView = arView | ||
| arView.session = sessionCoordinator.session | ||
| sceneUpdateSubscription = arView.scene.subscribe(to: SceneEvents.Update.self) { [weak self] event in | ||
| self?.drainPendingCommands() | ||
| self?.advancePresentation(by: event.deltaTime) | ||
| Task { @MainActor [weak self] in | ||
| await self?.drainPendingCommands() | ||
| self?.advancePresentation(by: event.deltaTime) | ||
| } | ||
| } | ||
| sessionCoordinator.onCapabilityStateChange = { [weak self] state in | ||
| self?.capabilityState = state | ||
|
|
@@ -69,7 +71,12 @@ final class CanonicalARSessionRuntime { | |
| self.commandHandlerOwner = nil | ||
| } | ||
| pendingCommands.removeAll(keepingCapacity: true) | ||
| report(render(.clearSession, in: arView)) | ||
| Task { @MainActor [weak self] in | ||
| guard let self, let view = self.arView else { return } | ||
| let res = await self.render(.clearSession, in: view) | ||
|
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On normal detachment, this task cannot run until the synchronous Useful? React with 👍 / 👎. |
||
| self.report(res) | ||
| self.companionState = .idle | ||
| } | ||
| sceneUpdateSubscription?.cancel() | ||
| sceneUpdateSubscription = nil | ||
| sessionStartTask?.cancel() | ||
|
|
@@ -83,15 +90,21 @@ final class CanonicalARSessionRuntime { | |
| guard let arView else { return } | ||
| if commands.contains(.clearSession) { | ||
| pendingCommands.removeAll(keepingCapacity: true) | ||
| report(render(.clearSession, in: arView)) | ||
| companionState = .idle | ||
| Task { @MainActor [weak self] in | ||
| guard let self, let view = self.arView else { return } | ||
| let res = await self.render(.clearSession, in: view) | ||
| self.report(res) | ||
| self.companionState = .idle | ||
| } | ||
| return | ||
| } | ||
|
|
||
| for command in commands { | ||
| enqueue(command) | ||
| } | ||
| drainPendingCommands() | ||
| Task { @MainActor [weak self] in | ||
| await self?.drainPendingCommands() | ||
| } | ||
| } | ||
|
|
||
| private func enqueue(_ command: ARWorldCommand) { | ||
|
|
@@ -119,12 +132,12 @@ final class CanonicalARSessionRuntime { | |
| } | ||
| } | ||
|
|
||
| private func drainPendingCommands() { | ||
| private func drainPendingCommands() async { | ||
| guard let arView else { return } | ||
| var index = pendingCommands.startIndex | ||
| while index < pendingCommands.endIndex { | ||
| let command = pendingCommands[index] | ||
| let result = render(command, in: arView) | ||
| let result = await render(command, in: arView) | ||
| report(result) | ||
| guard case .deferred = result else { | ||
| pendingCommands.remove(at: index) | ||
|
|
@@ -147,8 +160,11 @@ final class CanonicalARSessionRuntime { | |
| companionState = transition.resolvedState | ||
| } | ||
|
|
||
| private func render(_ command: ARWorldCommand, in arView: ARView) -> ARCommandResult { | ||
| renderCommandOverride?(command, arView) ?? renderer.render(command, in: arView) | ||
| private func render(_ command: ARWorldCommand, in arView: ARView) async -> ARCommandResult { | ||
| if let override = renderCommandOverride { | ||
| return override(command, arView) | ||
| } | ||
| return await renderer.render(command, in: arView) | ||
| } | ||
|
|
||
| private func report(_ result: ARCommandResult) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While a spawn is awaiting the 50 MB asset load, each scene update starts another unstructured task that enters
drainPendingCommands; the receive path can start an additional one as well. Multiple drains can therefore capture the same queue index, render the same command concurrently, and then remove that index after another drain already removed it, either dropping a later command or trapping with an out-of-range removal. Keep a single drain task or otherwise serialize queue ownership across suspension points.AGENTS.md reference: AGENTS.md:L24-L29
Useful? React with 👍 / 👎.