instantiateRenderEntity fails with multiple Application instances

ContainerResource.instantiateRenderEntity with multiple Application instances causing an error:

WebGL: INVALID_OPERATION: getShaderParameter: object does not belong to this context

This may be fixed passing an application reference to new Entity like this

instantiateRenderEntity(options, app) {
    const cloneHierarchy = (root, node, glb) => {

            const entity = new Entity(undefined, app);

By default this uses getApplication() which should get the same application you’re passing in as along as you call the instantiate from inside the update of the correct application?

In other words, where are you calling it from?

I’m calling it from outside the app. I have a react application that drives PC applications in components. This way getApplication() doesn’t work well. I have to pass correct application reference to all entities.

Also I’m not using global pc but loading engine as a package

I created an issue: Improve behaviour when multiple application instances are created · Issue #5752 · playcanvas/engine · GitHub

1 Like

We’re also running into this issue, we require async/await and have found that the “app” is the last application that did something rather than the one we’re currently using.
I also think we should probably deprecate the default export for “app” as convenient as it is its dangerous…

1 Like