menpo / menpo3d

Tools for manipulating 3D meshes within the Menpo project.
http://www.menpo.org
Other
165 stars 55 forks source link

Fix issues when creating multiple GL contexts in IPython cells #86

Closed patricksnape closed 2 years ago

patricksnape commented 2 years ago

We were seeing issues when writing code like this

rasterizer1 = menpo3d.rasterize.GLRasterizer(
    width=1024,
    height=1024,
    opengl_context=moderngl.create_context(standalone=True, backend="egl"),
)
rasterizer2 = menpo3d.rasterize.GLRasterizer(
    width=128,
    height=128,
    opengl_context=moderngl.create_context(standalone=True, backend="egl"),
)

In the same Jupyter cell. There seems to be some sort of race condition about which GLContext is active. Subsequent rendering calls would complain about not being able to build the program (or just crash the interpreter).

The only way I could convince the code to not crash was to lazily instantiate all buffers such that we guarantee they are active (via the contextmanager on the call to rasterize).

I also added a missing calling to self.opengl_ctx.finish() which caused random crashes when reading buffers for very large images.

patricksnape commented 2 years ago

No idea why Github isn't reporting CI:

https://app.circleci.com/pipelines/github/menpo/menpo3d/58/workflows/a966dde1-6bf4-4aa3-88d5-caeee94bb4ec

But it's all green (we don't have tests for rasterization so)