summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2017-09-29 16:57:53 +0200
committerJesus Fernandez <Jesus.Fernandez@qt.io>2017-10-02 16:09:40 +0000
commit2c0658fbb0279175cbe51381cbd71056835193e7 (patch)
treed841812cd81cd07f9c89997bf689e5af40d23632
parentd9952269b0660b48d3b5d1c1ef2f96fd13c69ed2 (diff)
Fix memory corruption
The previous implementation was adding the parameters to the function call after posting the event causing a random crash or memory corruption. Adding a function parameter to the createEvent function to be called before posting the event fixes the problem. Change-Id: I924cfe490372091afc6219d097d8c6bf17a43045 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
-rw-r--r--src/plugins/platforms/webgl/qwebglcontext.cpp41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/plugins/platforms/webgl/qwebglcontext.cpp b/src/plugins/platforms/webgl/qwebglcontext.cpp
index 4d55545..ca86d76 100644
--- a/src/plugins/platforms/webgl/qwebglcontext.cpp
+++ b/src/plugins/platforms/webgl/qwebglcontext.cpp
@@ -309,7 +309,7 @@ struct GLFunction
};
template<const GLFunction *Function>
-static QWebGLFunctionCall *createEvent(bool wait)
+static QWebGLFunctionCall *createEventImpl(bool wait)
{
auto context = QOpenGLContext::currentContext();
Q_ASSERT(context);
@@ -319,23 +319,46 @@ static QWebGLFunctionCall *createEvent(bool wait)
if (!clientData || !clientData->socket
|| clientData->socket->state() != QAbstractSocket::ConnectedState)
return nullptr;
- auto pointer = new QWebGLFunctionCall(Function->remoteName, handle->currentSurface(), wait);
- if (wait)
- QWebGLContextPrivate::waitingIds.insert(pointer->id());
- QCoreApplication::postEvent(QWebGLIntegrationPrivate::instance()->webSocketServer, pointer);
- return pointer;
+ return new QWebGLFunctionCall(Function->remoteName, handle->currentSurface(), wait);
+}
+
+static void postEventImpl(QWebGLFunctionCall *event)
+{
+ if (event->isBlocking())
+ QWebGLContextPrivate::waitingIds.insert(event->id());
+ QCoreApplication::postEvent(QWebGLIntegrationPrivate::instance()->webSocketServer, event);
+}
+
+template<const GLFunction *Function, class... Ts>
+static QWebGLFunctionCall *createEventAndPostImpl(bool wait, Ts&&... arguments)
+{
+ auto event = createEventImpl<Function>(wait);
+ if (event) {
+ addHelper(event, arguments...);
+ postEventImpl(event);
+ }
+ return event;
+}
+
+template<const GLFunction *Function>
+static QWebGLFunctionCall *createEventAndPostImpl(bool wait)
+{
+ auto event = createEventImpl<Function>(wait);
+ if (event)
+ postEventImpl(event);
+ return event;
}
template<const GLFunction *Function, class... Ts>
inline QWebGLFunctionCall *postEventImpl(bool wait, Ts&&... arguments)
{
- return addHelper(createEvent<Function>(wait), arguments...);
+ return createEventAndPostImpl<Function>(wait, arguments...);
}
template<const GLFunction *Function>
-inline QWebGLFunctionCall *postEventImpl(bool wait)
+inline QWebGLFunctionCall *postEvent(bool wait)
{
- return createEvent<Function>(wait);
+ return createEventAndPostImpl<Function>(wait);
}
template<const GLFunction *Function, class...Ts>