fix [#27589] Random crash with python UI
This script was defining an operator within the panels draw function, while its possible to support this its really asking for trouble. the fix is to raise an error when this happens. also fix crash passing non classes to register_class/unregister_class
This commit is contained in:
@@ -7158,8 +7158,25 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
|
||||
const char *identifier;
|
||||
PyObject *py_cls_meth;
|
||||
|
||||
if (!PyType_Check(py_class)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"register_class(...): "
|
||||
"expected a class argument, not '%.200s'", Py_TYPE(py_class)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass");
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"register_class(...): "
|
||||
"already registered as a subclass");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!pyrna_write_check()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"register_class(...): "
|
||||
"can't run in readonly state '%.200s'",
|
||||
((PyTypeObject *)py_class)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -7284,12 +7301,27 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
|
||||
StructRNA *srna;
|
||||
PyObject *py_cls_meth;
|
||||
|
||||
if (!PyType_Check(py_class)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"register_class(...): "
|
||||
"expected a class argument, not '%.200s'", Py_TYPE(py_class)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna) == NULL) {
|
||||
PWM_cursor_wait(0);
|
||||
PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass");
|
||||
return NULL;
|
||||
}*/
|
||||
|
||||
if (!pyrna_write_check()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"unregister_class(...): "
|
||||
"can't run in readonly state '%.200s'",
|
||||
((PyTypeObject *)py_class)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srna = pyrna_struct_as_srna(py_class, 0, "unregister_class(...):");
|
||||
if (srna == NULL)
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user