Lines drawn in VR mode stays forever

Hello,
I’m running a project from editor into Oculus Quest 2 and, when in VR mode, I’m drawing, in the update, a coloured line straight from the controller tip to show where user is pointing at.
In the first scene everything works well and I have a single line following the controller.
As soon as I change the scene the line from the controller still works but I can also see every line drawn in previous frames as they persists in the scene.
This happens whether the scene changes before or after VR session start.
This is the snippet I use to add a controller to the scene:

this.app.xr.input.on('add', function (inputSource) {            
        ....
    }, this);

Any idea?
Thanks in advance.

Are these lines you’re drawing from PlayCanvas?

Yes, here’s the call:

this.vecA.copy(this.inputSource.getOrigin());
this.vecB.copy(this.inputSource.getDirection());
this.vecB.scale(100).add(this.vecA)

this.app.drawLine(this.vecA, this.vecB, devXrRayColor);

bump

Hi, just to make it clearer, here’s a couple of screens


Do you have an idea of what the issue can be?
Thanks

Not sure, nothing comes to my mind. It little bit reminds me of this bug we used to have: App crashes when drawing lines to disabled layer · Issue #6345 · playcanvas/engine · GitHub

but that was fixed. Do you enable / disable layer you render lines to when you switch the scenes?

Try rendering lines to the world layer, use the layer parameter:

something like

this.app.drawLine(this.vecA, this.vecB, devXrRayColor, this.app.scene.layers.getLayerByName('World'));

but, considering this only happens when you switch the scene, I suspect there might be some issue with your scene switching, but not sure.

@SolidColor would be nice if you could create a blank project with a minimal repro of the issue.

Edit:
I tried to repro here, but couldn’t:
https://playcanvas.com/project/1296393/overview/draw-line-test

1 Like

Ok thanks for the answer. Adding world layer to the drawLine call does not solve the problem but I will setup a blank project and give you the link asap.
I wonder if this is due to scene switching since I don’t load a different scene but the same scene with different dynamically placed objects by destroying everything like this

        this.app.xr.input.off();
        this.app.off();

        var rootChildren = this.app.root.children;
        for (let i = 0; i < rootChildren.length; i++) {
            if (rootChildren[i].name !== 'CameraOffset' && rootChildren[i].name !== 'Controller') {
                rootChildren[i--].destroy();
            }
        }

and then loading settings and hierarchy this way

     this.app.scenes.loadSceneSettings(nextScene.url, function (ex) {
        if (ex) {
            console.error(ex.message);
        } else { }
    });

    this.app.scenes.loadSceneHierarchy(nextScene.url, (ex, entity) => {
        if (ex) {
            console.error(ex.message);
        } else { }
    });

Hi,
I reproduced the errore in this project: PlayCanvas | HTML5 Game Engine.

Principles and methods are copied from the original project so this is the exact same environment.
Here’s the play mode: PlayCanvas | HTML5 Game Engine

I really hope this helps.

1 Like

Thanks!

Hmm. @mvaligursky if you clone it, you need to change the template asset id in globals.js, since it will be different after cloning. Then use TAB to switch a scene. Quick inspection doesn’t show much. Spector seem to show the buffer contains old data?

@SolidColor you generally don’t want to hardcode an asset id, better use app.assets.find('Camera', 'template').