Forum Archive

GLKit view fails

Cethric

I have been updating the OpenGLES library to use the GLKit math libraries so that there is no externally required dependencies and in doing so I have noticed an issue with physics.
I have also seen another issue which isn't related to the math functions. When I create a GLKit GLKView it will work the first time however the second time it will fail.
Updated project here.

JonB

@Cethric Can you post an example that shows the issues you mentioned?

Cethric

@JonB, run the main.py file in the root of the library. On first run, you will notice that the camera will drop below the 'ground' and (usually with id 51) in the physics view the camera y position looks like it 'jumps'. On the second run without restarting Pythonista GLKView is a black screen and fails to register the added buttons or render anything.

JonB

I wonder if you are properly resetting everything. some of your modules rely, i think, on code getting executed during the import process, or depends on globals. But remember that modules might not get executed again when importing, yet globals get cleared..

Cethric

I will look into this and try resolving some of those issues.
@JonB any ideas on why the physics component would be failing still?

JonB

Fwiw, i noticed that physicsworld.js does not get added to glviewv the second time around. I am not actually seeing where it gets added in the first place, but since a webview only runs when it is presented, this is likely the issue of the black screen.

I have not delved deep enough to understand the physics problems.

Cethric

@JonB
Physics is handled under Util/Physics/__init__.py
The web view is loaded here

class CannonJS(object):
    def __init__(self):
        """
        Handle object for most Physics related tasks
        Attributes:
            setup (bool): Are the libraries setup yet
            objects (dict): This id of an object and the position and rotation of it
            js (ui.WebView): A method to display infomation and handle the JSContext
        """
        self.setup = False
        self.objects = {}
        self.js = ui.WebView()
        self.js.width = 800
        self.js.height = 300
        self.js.delegate = self
        self.js.load_html(get_library('view.html'))

        while not self.setup:
            pass

From line 55.
Then in main.py the physics world is loaded on lines 43 - 46

JonB

Print glviewv.subviews after the second run... no Webview is there. seems that the renderer.setup() never gets called. I suspect a problem with globals, but have not investigated further.

Also... are you "retaining" references to your delegate methods? omz had some examples where he stores them as attributes to ui, etc, (though a safer approach is to append them to a list, so they are not overwritten nedt time around). This is important when running multiple times, although i forget how the global clearing and module reloading logic works, whether site packages modules get deleted or not.

Cethric

I have updated the GitHub repo to represent the current work. I have more or less temporariely resolved the issue by calling reload(GLKit.view) in main.py how ever this is really only a temporary fix. I will look into some of the methods that omz uses to retain the globals/delegate methods.