-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running multiple engines creates errors in image-renderer #2622
Comments
Hi @jalyna Thanks for the kind words! Much appreciated! I agree multiple engines is definitely something that we'd want to be able to support. I think I know where the issue is in Excalibur, the GL context is stored in a singleton so when a new engine is created it tries to use the GL context created from another canvas, which matches the error message Problematic code: https://github.com/excaliburjs/Excalibur/blob/main/src/engine/Graphics/Context/webgl-adapter.ts Another possible temporary workaround until this is fixed would be to isolate each (or perhaps one) engine instance in it's own iframe? This might not be desirable understandably since iframes come with a lot of security baggage. You can use Here is a potential way to do it https://github.com/eonarheim/multi-excalibur-engine-workaround Hope this helps until this is fixed! |
@eonarheim Thank you so much for your quick answer 🙏🏻 I will try the iframe workaround, iframes these days are quite flexible so I think this will fit my use case. Thanks a lot! |
Closes #2622 Multi engine support is theoretically here! There are some big changes here: * TextureLoader is no longer a singleton, but an instance member on the `ExcaliburGraphicsContextWebGL` * We defer loading textures into webgl until the first draw call, this is needed to in order to upload to the multiple contexts. This shouldn't cause too much of an issue since we only need to do this if the image ever changes. * Additionally you must pass the gl context into the gl utility types Needs a little more testing to make sure everything is still good. There is potentially some more refactoring opportunities as well to make this feel a little cleaner <img width="1075" alt="image" src="https://user-images.githubusercontent.com/612071/236109108-0db4985e-7017-4609-8850-041fcd851806.png"> ## Changes: - Refactor TextureLoader to not be static - Remove webgl adapter and pass gl context to gl helper types
First: Thank you for your amazing work around excalibur. I really enjoy working with excaliburjs ⚔️
After reading the contributing guidelines I hope this is a qualifies as a new issue. I've been working on a little 2d game and wanted to add a second engine since I want to display a mini map that has its own camera and actors.
I'm not able to run 2 engines simultaneously as the first created engine will not be drawn correctly or in a funny way.
I'm not sure if this is something that excalibur wants to support but since the
graphicContext
is so well isolated I was suprised I was running into this issue. I created a minimal example for this.Steps to Reproduce
I also created a jsfiddle here: https://jsfiddle.net/kp1tLy4o/6/
As you can see I don't need to render anything for my second engine, it just has to exist.
This will not render the existing image and shows an error in the console:
If I don't create the second engine everything looks like expected.
Expected Result
I expect that the sprite is drawn.
Actual Result
Sprite is not drawn and I see above error message.
Environment
Current Workaround
If I run the engine initialization sequentially (so adding an
await createEngine1()
) I don't see the error and the sprite is drawn. In my actual game though I will add new actors dynamically in later stages, so just drawing something once is not really the solution for me.So far the issue only happens to me when using images, other resources have not been an issue.
The text was updated successfully, but these errors were encountered: