Page MenuHome

GPU: Free GPUOffScreens owned by Python when the corresponding context is discarded
Needs ReviewPublic

Authored by Jacques Lucke (JacquesLucke) on Nov 8 2018, 6:41 PM.

Details

Summary

Problem: When import gpu;offscreen=gpu.types.GPUOffScreen(100, 100) is run in the Python Console, and then the window is closed, Blender will crash. (in debug builds due to an assertion)

Possible Solutions:

  1. Ignore the problem, it is only in a debug build only anyway. Pretty sure that would cause other problems later...
  2. Free all framebuffers in the GPU_context_discard similar to the vaos. Would also have to update the Python objects, otherwise they think the framebuffers still exist.
  3. Keep track of the GPUOffScreen objects that are "owned" by Python and free them before the context is discarded.
  4. You could think that Pythons garbage collection solves this, but it doesn't... (think multiple windows; Python is "closed" after the opengl context is freed)

I talked with @Clément Foucault (fclem) about it and we decided to go with option 3 for now. So this is what this patch implements.
I'm fully aware that this is not a super nice solution and if someone has a better idea, please let me know!

Problems:

  • Using WITH_PYTHON does not work as I expected. Apparentely the GPU library is build without WITH_PYTHON even when Blender in general is compiled with Python. I don't know enough about cmake etc. to be able to understand this yet.

Diff Detail

Repository
rB Blender
Branch
offscreen_discard (branched from blender2.8)
Build Status
Buildable 2457
Build 2457: arc lint + arc unit

Event Timeline

Seems fine to me. I can't help for the Cmake thing I'm quite a noob too.

source/blender/python/gpu/gpu_py_offscreen.c
291

Use static and initialize to {NULL, NULL}.

source/blender/python/gpu/gpu_py_offscreen.h
43

put this line above the other typedef.