I agree! If you have a scene that calls another scene, over and over
again, it will grow the call stack more and more, just like you said.
To avoid that, you can do
Crafty.scene("scene A", function () {
// do stuff
setTimeout(function () {Crafty.scene("scene B")}, 0) //
asynchronous call to run the next scene
return;
});
I think that would work, and avoid both memory leaks and growing call
stack. But I'm not 100% sure, someone can correct me if I'm wrong.
Hmm, I have an idea: We could change the Crafty source code so that you can do:
Crafty.scene("scene A", function () {
// do stuff
return "scene B";
});
The Crafty.scene() would interpret a return-value with string type as
being another scene call. Wouldn't that be an improvement?
Steve
On Sun, Jun 9, 2013 at 10:11 AM, 曹磊 <
jump...@gmail.com> wrote:
> Hi,Steve
> I have another question about the scene.
>
> if I defined another scene ,for example:
> Crafty.scene("scene B", function_B)
> and the "scene B" will be called if something be triggered in "scene A",for
> example:
> var function_A = function(){
> ...
> if(something happened){
> Crafty.scene("scene B");
> }
>
> }
> My question is that when the Crafty.scene("scene B") was called, it will
> run,but the Crafty.scene("scene A") seems like unable to return. if this is
> true, when called repeatedly ,it may result in the stack overflow.
>
> 在 2013年5月17日星期五UTC+8下午8时11分11秒,Steve写道:
~~
Steven Byrnes
Postdoctoral Fellow, Applied Physics
Harvard University School of Engineering and Applied Sciences
http://sjbyrnes.com/