diff options
author | Campbell Barton <campbell@blender.org> | 2022-07-15 15:14:04 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-07-15 15:16:44 +0300 |
commit | 00dc7477022acdd969e4d709a235c0be819efa6c (patch) | |
tree | b6bd65095c8ce50520a638cddf2d843963369fc1 /source/blender/gpu | |
parent | 180db0f752c88d3bbd47774a0f7c9a31de5a3864 (diff) |
Fix T99706: Crash rendering with headless builds
When rendering with headless builds, show an error instead of crashing.
Previously GPU_backend_init was called indirectly from
DRW_opengl_context_create, a new function is now called from the window
manager (GPU_backend_init_once), so it's possible to check if the GPU
has a back-end.
This also disables the `bgl` Python module when building WITH_HEADLESS.
Reviewed By: fclem
Ref D15463
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/gpu/GPU_context.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_context.cc | 17 |
3 files changed, 15 insertions, 5 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 0cb92e02515..774f2a0f312 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -5,7 +5,7 @@ # to more easily highlight code-paths in other libraries that need to be refactored, # bf_gpu is allowed to have opengl regardless of this option. -if(NOT WITH_OPENGL AND NOT WITH_METAL_BACKEND) +if(NOT WITH_OPENGL AND NOT WITH_METAL_BACKEND AND NOT WITH_HEADLESS) add_definitions(-DWITH_OPENGL) endif() diff --git a/source/blender/gpu/GPU_context.h b/source/blender/gpu/GPU_context.h index 1fcd94c48fc..b04a4422baa 100644 --- a/source/blender/gpu/GPU_context.h +++ b/source/blender/gpu/GPU_context.h @@ -17,6 +17,7 @@ extern "C" { #endif +bool GPU_backend_init_once(void); void GPU_backend_init(eGPUBackendType backend); void GPU_backend_exit(void); bool GPU_backend_supported(eGPUBackendType type); diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc index 4a0a9ecc7f6..d3b208dc6f6 100644 --- a/source/blender/gpu/intern/gpu_context.cc +++ b/source/blender/gpu/intern/gpu_context.cc @@ -85,10 +85,7 @@ Context *Context::get() GPUContext *GPU_context_create(void *ghost_window) { - if (GPUBackend::get() == nullptr) { - /* TODO: move where it make sense. */ - GPU_backend_init(GPU_BACKEND_OPENGL); - } + GPU_backend_init_once(); Context *ctx = GPUBackend::get()->context_alloc(ghost_window); @@ -214,6 +211,18 @@ bool GPU_backend_supported(eGPUBackendType type) } } +bool GPU_backend_init_once() +{ + if (GPUBackend::get() == nullptr) { + if (!GPU_backend_supported(GPU_BACKEND_OPENGL)) { + return false; + } + /* TODO: move where it make sense. */ + GPU_backend_init(GPU_BACKEND_OPENGL); + } + return true; +} + void GPU_backend_init(eGPUBackendType backend_type) { BLI_assert(g_backend == nullptr); |