Skip to content
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

Tearing down a webgl Pixi renderer and clearing cache #460

Closed
alexkehayias opened this issue Dec 29, 2013 · 18 comments
Closed

Tearing down a webgl Pixi renderer and clearing cache #460

alexkehayias opened this issue Dec 29, 2013 · 18 comments
Labels
🤔 Question User question, similar to Help Wanted or Needs Help. These can be addressed whenever someone has tim

Comments

@alexkehayias
Copy link

Is there a way of tearing down a Pixi renderer so that it cleans up after itself (clearing any shared resources) so that a new instance can be created without any references to the old webgl context? I get an error about references to a different webgl context when removing a renderer canvas and creating a new one.

Shared context appears to be the problem (as per issues #298 #181 #23) that people experience when trying to use multiple webgl renderers at the same time, but it also happens if you remove the canvas and re-create it without a page reload.

@mattdesl
Copy link
Contributor

Pixi uses a lot of globals (like BaseTextureCache and TextureCache) which is the main issue. If you clear those the browser should eventually get around to deleting the old WebGL context. It would be cleaner if Pixi explicitly deletes resources, though. We'd need to add the following features;

  • Delete textures -- currently bugged, see gl.deleteTexture type error #446
  • Disable vertex attributes and delete all shaders
  • Delete all vertex/index buffers
  • Delete all frame buffer objects

IMHO it would be good to consider context loss since it's related to the whole aspect of context creation/teardown #357, and it will become more pertinent when WebGL support improves on mobile devices.

Generally speaking you should do your best just to have one WebGL context, and re-use it, instead of constantly creating/destroying WebGL contexts.

@alexkehayias
Copy link
Author

Thanks for the reply!

Looks like pull request #347 does most of the cache clearing and would be a good starting point. Only difference seems to be I'm not trying to restore the original context. Is that accurate?

@mattdesl
Copy link
Contributor

Yeah. #357 is more about context loss events (which can happen at any time with WebGL, mainly on mobile), and recovering from them without forcing your user to re-load the page. In your case, things should work if you just clear the texture/shader/whatever globals.

@drkibitz
Copy link
Contributor

drkibitz commented Jan 3, 2014

@GoodBoyDigital @mattdesl Lots of great work happening that I have been perusing on vacation 🎆

Still a little confused about the context handling overall. I see the introduction of context IDs, and breaking things out into managers, but there still seems to be a global context hanging around and referenced in a couple places. Just wondering if there is still some more cleanup to be done? Maybe just in src/pixi/renderers/webgl/WebGLRenderer.js?

@mattdesl
Copy link
Contributor

mattdesl commented Jan 3, 2014

Just peering at the additions now.

I'd be careful with adding properties to an object after creation, since it's not optimal for V8. I'm sure it's not such a huge deal though..

Overall the changes look good, and will probably make contributions much easier in the future! 👍

@drkibitz
Copy link
Contributor

drkibitz commented Jan 4, 2014

@mattdesl I've seen that too. I guess since the ids are integers, would an array be more optimal in this case?

@GoodBoyDigital
Copy link
Member

Interesting stuff!

@drkibitz Yes there could very well be some clean up to be done. There is one global reference for the default renderer to help simplify using render textures. Mainly because creating and using a render texture requires that it knows which context it belongs to. Figured as most people will still only use one renderer on screen that the global default renderer can be used if none is passed to it.

Happy to take suggestions on how to make that a little better. Maybe a render texture should have the renderer passed to it through its constructor?

Other than that there should be know more global variables in PIXI other than some constants and the texture cache.

@mattdesl Good call! I will definitely be going through and checking that its optimal for v8. I think the majority of the codebase should be fine - but I'm sure theres probably a view variables that will need to be set in the constructor that may not be right now. Let me know if you bump into any!

Thanks guys!

@drkibitz
Copy link
Contributor

drkibitz commented Jan 7, 2014

@GoodBoyDigital thanks for trying, but still confused. Looks to me that RenderTexture already has a reference to the renderer https://github.com/GoodBoyDigital/pixi.js/blob/master/src/pixi/textures/RenderTexture.js#L52

Unless you made this change after that comment ;)

@GoodBoyDigital
Copy link
Member

@drkibitz oh! you are indeed correct, must have changed it without remembering - its been a busy pixi week :)

@GoodBoyDigital
Copy link
Member

You have a good eye! You have every right to be confused by them too - they are either legacy or need tweaking. Will make sure to sort those out next. Thanks for pointing them out!

@englercj
Copy link
Member

englercj commented Feb 9, 2014

Can this issue be closed, or is it still open?

@alexkehayias
Copy link
Author

I vote close. It's not a bug more a a feature request. The workaround for
now is to use the html5 canvas renderer rather than WebGL. Also looks like
this will be easier to do with the webgl renderer once more of the cleanups
proposed earlier happen.

On Sunday, February 9, 2014, Chad Engler notifications@github.com wrote:

Can this issue be closed, or is it still open?

Reply to this email directly or view it on GitHubhttps://github.com//issues/460#issuecomment-34585027
.

@GoodBoyDigital
Copy link
Member

Cool - nows probably a good time to mention there is actually some tear down code in the webGL render now so it can now be destroyed :)

@alexkehayias
Copy link
Author

Thanks will check out the latest!

On Sunday, February 9, 2014, Mat Groves notifications@github.com wrote:

Closed #460 #460.

Reply to this email directly or view it on GitHubhttps://github.com//issues/460
.

@GoodBoyDigital
Copy link
Member

rad! let me know if it all works ok for you!

@lock
Copy link

lock bot commented Feb 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤔 Question User question, similar to Help Wanted or Needs Help. These can be addressed whenever someone has tim
Projects
None yet
Development

No branches or pull requests

5 participants