Teardown OpenFL


#1

How to correctly cleanup and restart OpenFL?

I am using the npm version where I manually initiate everything (new Stage() and appendChild(stage.element)). I wonder how to completely tear down such a OpenFL instance.

In particular, in my app I have a Video instance. Currently my “tear down” strategy is to remove all children from the stage and call close() on the video’s NetStream. But in the next launch the video is no longer showing, with whole bunch of WebGL warnings (e.g. INVALID_VALUE: disableVertexAttribArray: index out of range)

Advice appreciated. Thanks.


#2

If you null the Stage, does it eventually get garbage collected?

Come to think of it, I have a feeling it might not, as the Lime application will have events to the window, and disabling the stage will still leave the Lime application behind it.

Do you think stage.dispose () would be a good API to have? Other recommendations are welcome as well.

I think we would need to stop rendering, call renderer.setShader (null) to disable the current shader, and call application.exit (though this may a non-op on HTML5).

I think the biggest problem is that right now, new Stage does not operate within a closure. This means Haxe static values are global, across multiple instances. As a result, a static value from the first run “contaminates” the second run.

I am trying to find where someone had OpenFL working properly within a closure, but it required changes to how the JavaScript was generated from Haxe, and I wanted to avoid altering the file afterwards. However, on NPM we already are using hxgenjs to generate CommonJS modules, so we’re already removed from a straight Haxe -> JS compile. It would be really, really great to think of whether we should have new Stage working in isolation, or if we have to design OpenFL around avoiding statics.


#3

Yeah dispose() would be an excellent API from users’ perspective.

Btw, what is the proper way to cleanup a Video instance?


#4

I think there are some places we need to add extra null checks, in the case that netStream.dispose () is called (while still attached to a Video instance).

Perhaps calling netStream.close() then video.visible = false to disable rendering?

I’ll look at this soon if I can, just a little bit of tidying here. I think (almost all?) projects to date don’t teardown except when the page is closed entirely


#5

Nvm, don’t wanna make it too urgent for you. Currently I can work around it by using a single OpenFL instance but hide it (with DOM magic) when not used.


#6

This should help:

I’ll keep looking at adding a dispose() method (or similar) for cleaning up a Stage