Skip to content

Commit 777b046

Browse files
Kaloyan ChehlarskiAllan Sandfeld Jensen
authored andcommitted
Fix crash in WGL context creation
GLContextWGL::Initialize() gets called before OpenGL extensions get bound to the driver object, causing a nullptr dereference crash when using OpenGL as the RHI backend. This change modifies the GL bindings generation script to force it to produce code that checks whether the problem function has been bound already or not. The WGL context code that uses the function already handles cases where it receives nullptr as return value, so the initialization succeeds. Fixes: QTBUG-124370 Change-Id: I53f885cd962ef7feb8c71b8a10c7d17684c43149 Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/554966 Reviewed-by: Allan Sandfeld Jensen <[email protected]> Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/560809 Reviewed-by: Peter Varga <[email protected]>
1 parent 7e0aedc commit 777b046

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

chromium/ui/gl/generate_bindings.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
function. This may happen for example when functions
4444
are added to a new version of an extension, but the
4545
extension string is not modified.
46+
check_for_nullptr: Workaround for QTBUG-124370. Adds a check that ensures
47+
the function has been bound already.
4648
By default, the function gets its name from the first name in its names or
4749
versions array. This can be overridden by supplying a 'known_as' key.
4850
@@ -2980,7 +2982,8 @@
29802982
'arguments': 'HDC hdc', },
29812983
{ 'return_type': 'HGLRC',
29822984
'names': ['wglCreateContextAttribsARB'],
2983-
'arguments': 'HDC hDC, HGLRC hShareContext, const int* attribList', },
2985+
'arguments': 'HDC hDC, HGLRC hShareContext, const int* attribList',
2986+
'check_for_nullptr': True, },
29842987
{ 'return_type': 'HGLRC',
29852988
'names': ['wglCreateLayerContext'],
29862989
'arguments': 'HDC hdc, int iLayerPlane', },
@@ -3727,8 +3730,12 @@ def MakeArgNames(arguments):
37273730
file.write(' driver_->fn.%sFn(%s);\n' %
37283731
(function_name, argument_names))
37293732
else:
3730-
file.write(' return driver_->fn.%sFn(%s);\n' %
3731-
(function_name, argument_names))
3733+
if ('check_for_nullptr' in func):
3734+
file.write(' return driver_->fn.%sFn ?\n driver_->fn.%sFn(%s)\n : nullptr;\n' %
3735+
(function_name, function_name, argument_names))
3736+
else:
3737+
file.write(' return driver_->fn.%sFn(%s);\n' %
3738+
(function_name, argument_names))
37323739
file.write('}\n')
37333740

37343741
# Write TraceGLApi functions

chromium/ui/gl/gl_bindings_autogen_wgl.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ HGLRC WGLApiBase::wglCreateContextFn(HDC hdc) {
124124
HGLRC WGLApiBase::wglCreateContextAttribsARBFn(HDC hDC,
125125
HGLRC hShareContext,
126126
const int* attribList) {
127-
return driver_->fn.wglCreateContextAttribsARBFn(hDC, hShareContext,
128-
attribList);
127+
return driver_->fn.wglCreateContextAttribsARBFn
128+
? driver_->fn.wglCreateContextAttribsARBFn(hDC, hShareContext,
129+
attribList)
130+
: nullptr;
129131
}
130132

131133
HGLRC WGLApiBase::wglCreateLayerContextFn(HDC hdc, int iLayerPlane) {

0 commit comments

Comments
 (0)