Error 'getHitTestResults' on 'XRFrame': Unable to obtain hit test results for specified hit test

With the attached script, in entry of WebXR on Android, I can get the hitTestResults, but when I exit and re-enter WebXR AR after, I get this error below and I can’t access the hitTestResults?

{"stack": "Error: Failed to execute 'getHitTestResults' on 'XRFrame': Unable to obtain hit test results for specified hit test source. Ensure that it was not already canceled.\n    at WebXRInterface.onUpdate

WebXRInterface.ts

Original Post on Discord

by user 103054507105067008

Is there a way to check if an XRHitTestSource has been cancelled before I get the hitTestResults?

  onUpdate(session: XRSession, frame: XRFrame) {
    //console.log("hittestsouurce: ",this.hitTestSource);
    if (!this.hitTestSource) return;
    //console.log("update");
    const hitTestResults = frame.getHitTestResults(this.hitTestSource);
    if (hitTestResults.length) {

by user 103054507105067008

Mh so a note: when using onBeforeRender it is the xrFrame that we get from three.js. I’m not sure why it should be cancelled / not work anymore the second time (we use it as well when placing the Reticle)

Just for testing: do you get the same result with this.context.xrFrame ? It should be the same object tho so lead to the same result, just to be sure

Same issue there when I try

    const hitTestResults = this.context.xrFrame?.getHitTestResults(
      this.hitTestSource
    );

by user 103054507105067008

could it be caused by the hitTestSource being re-used?

at least for a few frames?

since it is deferred and the second time you enter XR you still have the source from the session before
image.png

so this might fix it
image.png

Hell yeah that worked! Thankyou so much!

by user 103054507105067008

Was probably a silly mistake on my part but I wasn’t sure if the source was reused

by user 103054507105067008

Nice! Happy to hear