mirror of
https://github.com/thp/pyotherside.git
synced 2025-01-28 23:52:55 +08:00
Added null-checks for callbacks.
This commit is contained in:
parent
3e4ea6ee5f
commit
52e75e918f
@ -19,6 +19,8 @@
|
|||||||
#include "qpython_priv.h"
|
#include "qpython_priv.h"
|
||||||
#include "pyglrenderer.h"
|
#include "pyglrenderer.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
|
||||||
PyGLRenderer::PyGLRenderer()
|
PyGLRenderer::PyGLRenderer()
|
||||||
: m_paintGLCallable(0)
|
: m_paintGLCallable(0)
|
||||||
@ -72,20 +74,26 @@ void PyGLRenderer::setRect(QRect rect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PyGLRenderer::init() {
|
void PyGLRenderer::init() {
|
||||||
if (!m_initialized) {
|
if (m_initialized)
|
||||||
if (!m_initGL.isEmpty()) {
|
return;
|
||||||
QPythonPriv *priv = QPythonPriv::instance();
|
|
||||||
priv->enter();
|
if (!m_initGL.isEmpty()) {
|
||||||
PyObject *initGLCallable = priv->eval(m_initGL);
|
QPythonPriv *priv = QPythonPriv::instance();
|
||||||
PyObject *args = PyTuple_New(0);
|
priv->enter();
|
||||||
PyObject *o = PyObject_Call(initGLCallable, args, NULL);
|
PyObject *initGLCallable = priv->eval(m_initGL);
|
||||||
if (o) Py_DECREF(o); else PyErr_PrintEx(0);
|
if (!initGLCallable) {
|
||||||
Py_DECREF(args);
|
qWarning() << "Init callback " << m_initGL << " not defined.";
|
||||||
Py_DECREF(initGLCallable);
|
|
||||||
priv->leave();
|
priv->leave();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
m_initialized = true;
|
PyObject *args = PyTuple_New(0);
|
||||||
|
PyObject *o = PyObject_Call(initGLCallable, args, NULL);
|
||||||
|
if (o) Py_DECREF(o); else PyErr_PrintEx(0);
|
||||||
|
Py_DECREF(args);
|
||||||
|
Py_DECREF(initGLCallable);
|
||||||
|
priv->leave();
|
||||||
}
|
}
|
||||||
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -96,8 +104,15 @@ void PyGLRenderer::paint()
|
|||||||
|
|
||||||
QPythonPriv *priv = QPythonPriv::instance();
|
QPythonPriv *priv = QPythonPriv::instance();
|
||||||
priv->enter();
|
priv->enter();
|
||||||
if (!m_paintGLCallable)
|
|
||||||
|
if (!m_paintGLCallable) {
|
||||||
m_paintGLCallable = priv->eval(m_paintGL);
|
m_paintGLCallable = priv->eval(m_paintGL);
|
||||||
|
if (!m_paintGLCallable) {
|
||||||
|
qWarning() << "Paint callback " << m_paintGL << " not defined.";
|
||||||
|
priv->leave();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Call the paintGL callback with arguments x, y, width, height.
|
// Call the paintGL callback with arguments x, y, width, height.
|
||||||
// These are the boundaries in which the callback should render,
|
// These are the boundaries in which the callback should render,
|
||||||
@ -122,16 +137,22 @@ void PyGLRenderer::paint()
|
|||||||
|
|
||||||
void PyGLRenderer::cleanup()
|
void PyGLRenderer::cleanup()
|
||||||
{
|
{
|
||||||
if (!m_cleanupGL.isEmpty()) {
|
if (m_cleanupGL.isEmpty())
|
||||||
QPythonPriv *priv = QPythonPriv::instance();
|
return;
|
||||||
priv->enter();
|
|
||||||
PyObject *cleanupGLCallable = priv->eval(m_cleanupGL);
|
QPythonPriv *priv = QPythonPriv::instance();
|
||||||
PyObject *args = PyTuple_New(0);
|
priv->enter();
|
||||||
PyObject *o = PyObject_Call(cleanupGLCallable, args, NULL);
|
PyObject *cleanupGLCallable = priv->eval(m_cleanupGL);
|
||||||
if (o) Py_DECREF(o); else PyErr_PrintEx(0);
|
if (!cleanupGLCallable) {
|
||||||
m_initialized = true;
|
qWarning() << "Cleanup callback " << m_cleanupGL << " not defined.";
|
||||||
Py_DECREF(args);
|
|
||||||
Py_DECREF(cleanupGLCallable);
|
|
||||||
priv->leave();
|
priv->leave();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
PyObject *args = PyTuple_New(0);
|
||||||
|
PyObject *o = PyObject_Call(cleanupGLCallable, args, NULL);
|
||||||
|
if (o) Py_DECREF(o); else PyErr_PrintEx(0);
|
||||||
|
m_initialized = true;
|
||||||
|
Py_DECREF(args);
|
||||||
|
Py_DECREF(cleanupGLCallable);
|
||||||
|
priv->leave();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user