Skip to content

Commit

Permalink
fix: handle persistent anchor setting failure
Browse files Browse the repository at this point in the history
We remove oldest anchor if the set is full
  • Loading branch information
hi-liang committed Dec 8, 2023
1 parent ceb4e4a commit 7f3cad4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/systems/armarker/armarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import CVWorkerMsgs from './worker-msgs';
import { ARENA_EVENTS } from '../../constants';
import { ARENAUtils } from '../../utils';

const MAX_PERSISTENT_ANCHORS = 7;

/**
* ARMarker System. Supports ARMarkers in a scene.
* @module armarker-system
Expand Down Expand Up @@ -517,10 +519,21 @@ AFRAME.registerSystem('armarker', {
// Delete the old anchor
this.webXRSession.deletePersistentAnchor(oldPersistAnchor);
}
anchor.requestPersistentHandle().then((handle) => {
// Save the new one
window.localStorage.setItem('originAnchor', handle);
});
// Check how many anchors there are, Quest has a low limit currently
if (this.webXRSession.persistentAnchors.size >= MAX_PERSISTENT_ANCHORS) {
// Delete the oldest anchor
const oldestAnchor = this.webXRSession.persistentAnchors.values().next().value;
this.webXRSession.deletePersistentAnchor(oldestAnchor);
}
anchor
.requestPersistentHandle()
.then((handle) => {
// Save the new one
window.localStorage.setItem('originAnchor', handle);
})
.catch((err) => {
console.error('Could not persist anchor', err);
});
} else if (this.originAnchor) {
this.originAnchor.delete();
}
Expand Down

0 comments on commit 7f3cad4

Please sign in to comment.