Fix #141132: Crash on background GP render

The crash seems to come from libepoxy GL functions pointing to null.
It seems that libepoxy "Automatically initializes as new GL functions are used."
and that to call a function without a GL context bound, the function
must have been called before with a bound context.

This just modifies the scope of the context binding from
DRW_module_exit to  RE_engines_exit, which seems the safest solution
for 4.5.

Pull Request: https://projects.blender.org/blender/blender/pulls/141233
This commit is contained in:
Miguel Pozo
2025-07-01 15:24:45 +02:00
parent 61d51a5643
commit e2b898fea7
2 changed files with 8 additions and 9 deletions

View File

@@ -2089,17 +2089,10 @@ void DRW_module_init()
void DRW_module_exit()
{
if (DRW_gpu_context_try_enable() == false) {
/* Nothing has been setup. Nothing to clear. */
return;
}
GPU_TEXTURE_FREE_SAFE(g_select_buffer.texture_depth);
GPU_FRAMEBUFFER_FREE_SAFE(g_select_buffer.framebuffer_depth_only);
DRW_shaders_free();
DRW_gpu_context_disable();
}
/** \} */

View File

@@ -63,8 +63,14 @@ void RE_engines_exit()
{
RenderEngineType *type, *next;
DRW_engines_free();
DRW_module_exit();
if (DRW_gpu_context_try_enable()) {
/* Clean resources if the DRW context exists.
* We need a context bound even when dealing with non context dependent GPU resources,
* since GL functions may be null otherwise (See #141233). */
DRW_engines_free();
DRW_module_exit();
DRW_gpu_context_disable();
}
for (type = static_cast<RenderEngineType *>(R_engines.first); type; type = next) {
next = type->next;