Forum

Load json in function of a parameter

09 November 2016 10:49
Hi,

Like view in a previous post (here), I encounter memory leak with json in Firefox when I use physics on my scene.

For a project, I have many scenes controlled by the same couple of js but I don't need physics for all scenes. I know I don't resolv this problem of memory leak but I would still limit this.

So, I want, in function of the scene load, that the script choose if it use physics or not. To check if I need physics in my scene, I check if a certain object is present in my blender scene, so it's after the loading scene while the choice of the physics must do before this. I think I am obliged to reload my page to apply this choice.

To reload my page with a param, I think I must write a param in the URL. Or have you an other solution ? To check that, I write a code inspiring me to this topic. I have this code :

exports.init = function () {

        var url_params = m_app.get_url_params();
        var adress = window.location;

        if (!url_params)
            adress += "?quality=true";
        
        window.location.replace(adress);

        var use_physics = "false";
        if (url_params && "quality" in url_params)
            use_physics = url_params["quality"];


        m_app.init({
            canvas_container_id: "main_canvas_container",
            callback: init_cb,
            physics_enabled: use_physics,
        });
    }


For the moment, I ignore if the scene needs physics or not, I just want rewrite the URL but I have this error when I use << window.location.replace(adress); >> :
B4W ERROR : Unable to unload data !


To resume, my questions are :
Rewrite URL with param is the best solution ?
My code is it correct ?
What is this error ?

Thanks in advance.
I'm not crazy ! My reality is just different than yours.
10 November 2016 15:03
Hi!
If a scene doesn't have the Enable Physics flag enabled in its settings, physics won't be initialized regardless of the physics_enabled flag under the init function.
So this situation should be processed by the engine automatically.
17 November 2016 11:37
Hi, sorry for the late answer.

What you say is wrong in my case :
If I activate Enable Physics in Blender and don't reference physics_enabled, I have the bug, so physics is activate.
If I deactivate Enable Physics in Blender and don't reference physics_enabled, I have the bug, so physics is activate.
If I activate Enable Physics in Blender and reference false for physics_enabled, It's ok, so physics is not activate.
If I deactivate Enable Physics in Blender and reference false for physics_enabled, It's ok, so physics is not activate.
If I deactivate Enable Physics in Blender and reference true for physics_enabled, I have the bug, so physics is activate.

After, I solved my problem for the URL, I had forgotten m_app in the first line :
var url_params = m_app.get_url_params(m_app);

So my solution for the moment is :
exports.init = function () {
        //check in url to activate physics or not
        var url_params = m_app.get_url_params(m_app);
        var use_physics = false;

        if (url_params && "physics" in url_params) {
            var str = url_params["physics"];
            if (str == "true")
                use_physics = true;
        }

        m_app.init({
            canvas_container_id: "main_canvas_container",
            callback: init_cb,
            physics_enabled: use_physics
        });
    }
And the switch :
if (obj_player_floor != null) {
        //reload page to activate physics
        var url_params = m_app.get_url_params(m_app);
        var adress = window.location.href;
        if (!url_params) {
            adress += "?physics=true";
            window.location.href = adress;
            return;
        }
}


Now, my scenes that need physics are loaded twice and bug with the memory leak in firefox but my scenes that don't need physics works great.
I'm not crazy ! My reality is just different than yours.
17 November 2016 13:02
hope this bug will be resolved soon. It's quite important
18 November 2016 13:36
What you say is wrong in my case :
If I activate Enable Physics in Blender and don't reference physics_enabled, I have the bug, so physics is activate.
If I deactivate Enable Physics in Blender and don't reference physics_enabled, I have the bug, so physics is activate.
If I activate Enable Physics in Blender and reference false for physics_enabled, It's ok, so physics is not activate.
If I deactivate Enable Physics in Blender and reference false for physics_enabled, It's ok, so physics is not activate.
If I deactivate Enable Physics in Blender and reference true for physics_enabled, I have the bug, so physics is activate.

I have tested the described cases and wasn't able to reproduce any of these bugs. Could you please attach a small project where this behavior is reproduced?
 
Please register or log in to leave a reply.