Page MenuHome
Paste P877

patch for T59773
ActivePublic

Authored by Germano Cavalcante (mano-wii) on Dec 24 2018, 11:01 PM.
diff --git a/source/blender/gpu/GPU_init_exit.h b/source/blender/gpu/GPU_init_exit.h
index e89c970b7d9..8f1a42c8795 100644
--- a/source/blender/gpu/GPU_init_exit.h
+++ b/source/blender/gpu/GPU_init_exit.h
@@ -38,6 +38,7 @@ extern "C" {
void GPU_init(void);
void GPU_exit(void);
+bool GPU_is_initialized(void);
#ifdef __cplusplus
}
diff --git a/source/blender/gpu/intern/gpu_init_exit.c b/source/blender/gpu/intern/gpu_init_exit.c
index 55d0466c929..d21acb188d9 100644
--- a/source/blender/gpu/intern/gpu_init_exit.c
+++ b/source/blender/gpu/intern/gpu_init_exit.c
@@ -73,7 +73,6 @@ void GPU_init(void)
}
-
void GPU_exit(void)
{
if (!G.background) {
@@ -92,3 +91,9 @@ void GPU_exit(void)
initialized = false;
}
+
+
+bool GPU_is_initialized(void)
+{
+ return initialized;
+}
diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c
index 5f1ea7a33ce..25ffd768a07 100644
--- a/source/blender/python/gpu/gpu_py_shader.c
+++ b/source/blender/python/gpu/gpu_py_shader.c
@@ -29,6 +29,7 @@
#include "BLI_utildefines.h"
+#include "GPU_init_exit.h"
#include "GPU_shader.h"
#include "GPU_shader_interface.h"
@@ -721,6 +722,11 @@ static PyObject *bpygpu_shader_from_builtin(PyObject *UNUSED(self), PyObject *ar
return NULL;
}
+ if (!GPU_is_initialized()) {
+ PyErr_SetString(PyExc_SystemError, "This function can not be called without a GPU context");
+ return NULL;
+ }
+
GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
return BPyGPUShader_CreatePyObject(shader, true);
diff --git a/source/blender/python/gpu/gpu_py_types.c b/source/blender/python/gpu/gpu_py_types.c
index d9ef0736f8e..b767ee1b56c 100644
--- a/source/blender/python/gpu/gpu_py_types.c
+++ b/source/blender/python/gpu/gpu_py_types.c
@@ -27,6 +27,10 @@
#include <Python.h>
+#include "BLI_utildefines.h"
+
+#include "GPU_init_exit.h"
+
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
@@ -43,12 +47,31 @@ static struct PyModuleDef BPyGPU_types_module_def = {
.m_name = "gpu.types",
};
+static PyObject *bpygpu_type_new_error(
+ PyTypeObject *UNUSED(type),
+ PyObject *UNUSED(args),
+ PyObject *UNUSED(kwds))
+{
+ PyErr_SetString(PyExc_SystemError, "This object can not be created without a GPU context");
+ return NULL;
+}
+
PyObject *BPyInit_gpu_types(void)
{
PyObject *submodule;
submodule = PyModule_Create(&BPyGPU_types_module_def);
+ if (!GPU_is_initialized()) {
+ /* Warning: Only restarting Blender for it to work again. */
+ BPyGPUVertFormat_Type.tp_new = bpygpu_type_new_error;
+ BPyGPUVertBuf_Type.tp_new = bpygpu_type_new_error;
+ BPyGPUIndexBuf_Type.tp_new = bpygpu_type_new_error;
+ BPyGPUBatch_Type.tp_new = bpygpu_type_new_error;
+ BPyGPUOffScreen_Type.tp_new = bpygpu_type_new_error;
+ BPyGPUShader_Type.tp_new = bpygpu_type_new_error;
+ }
+
if (PyType_Ready(&BPyGPUVertFormat_Type) < 0)
return NULL;
if (PyType_Ready(&BPyGPUVertBuf_Type) < 0)