Fix T94268: Closing SteamVR and restarting VR Session crashes Blender
Crash was caused since the function pointers `s_xrGetOpenGLGraphicsRequirementsKHR_fn`/ `s_xrGetD3D11GraphicsRequirementsKHR_fn` were static and were not updated with the correct proc address after being set the first time. As stated in the OpenXR spec: "function pointers returned by xrGetInstanceProcAddr using one XrInstance may not be valid when used with objects related to a different XrInstance". Although it would seem reasonable that the proc address would not change if the instance was the same (hence the `static XrInstance s_instance;`), in testing, repeated calls to `xrGetInstanceProcAddress()` with the same instance still can result in changes (at least for the SteamVR runtime) so the workaround is to simply set the function pointers every time, essentially trivializing their `static` designations. Reviewed By: Severin Maniphest Tasks: T94268 Differential Revision: https://developer.blender.org/D14023
This commit is contained in:
parent
b38f40e904
commit
4fbd00e04c
Notes:
blender-bot
2023-02-14 05:25:44 +01:00
Referenced by issue #94268, Closing SteamVR and restarting VR Session crashes Blender
|
@ -84,16 +84,26 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
|
|||
#endif
|
||||
static PFN_xrGetOpenGLGraphicsRequirementsKHR s_xrGetOpenGLGraphicsRequirementsKHR_fn =
|
||||
nullptr;
|
||||
// static XrInstance s_instance = XR_NULL_HANDLE;
|
||||
XrGraphicsRequirementsOpenGLKHR gpu_requirements = {XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR};
|
||||
const XrVersion gl_version = XR_MAKE_VERSION(
|
||||
ctx_gl.m_contextMajorVersion, ctx_gl.m_contextMinorVersion, 0);
|
||||
|
||||
/* Although it would seem reasonable that the proc address would not change if the instance was
|
||||
* the same, in testing, repeated calls to #xrGetInstanceProcAddress() with the same instance
|
||||
* can still result in changes so the workaround is to simply set the function pointer every
|
||||
* time (trivializing its 'static' designation). */
|
||||
// if (instance != s_instance) {
|
||||
// s_instance = instance;
|
||||
s_xrGetOpenGLGraphicsRequirementsKHR_fn = nullptr;
|
||||
//}
|
||||
if (!s_xrGetOpenGLGraphicsRequirementsKHR_fn &&
|
||||
XR_FAILED(xrGetInstanceProcAddr(
|
||||
instance,
|
||||
"xrGetOpenGLGraphicsRequirementsKHR",
|
||||
(PFN_xrVoidFunction *)&s_xrGetOpenGLGraphicsRequirementsKHR_fn))) {
|
||||
s_xrGetOpenGLGraphicsRequirementsKHR_fn = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
s_xrGetOpenGLGraphicsRequirementsKHR_fn(instance, system_id, &gpu_requirements);
|
||||
|
@ -305,14 +315,24 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
|
|||
std::string *r_requirement_info) const override
|
||||
{
|
||||
static PFN_xrGetD3D11GraphicsRequirementsKHR s_xrGetD3D11GraphicsRequirementsKHR_fn = nullptr;
|
||||
// static XrInstance s_instance = XR_NULL_HANDLE;
|
||||
XrGraphicsRequirementsD3D11KHR gpu_requirements = {XR_TYPE_GRAPHICS_REQUIREMENTS_D3D11_KHR};
|
||||
|
||||
/* Although it would seem reasonable that the proc address would not change if the instance was
|
||||
* the same, in testing, repeated calls to #xrGetInstanceProcAddress() with the same instance
|
||||
* can still result in changes so the workaround is to simply set the function pointer every
|
||||
* time (trivializing its 'static' designation). */
|
||||
// if (instance != s_instance) {
|
||||
// s_instance = instance;
|
||||
s_xrGetD3D11GraphicsRequirementsKHR_fn = nullptr;
|
||||
//}
|
||||
if (!s_xrGetD3D11GraphicsRequirementsKHR_fn &&
|
||||
XR_FAILED(xrGetInstanceProcAddr(
|
||||
instance,
|
||||
"xrGetD3D11GraphicsRequirementsKHR",
|
||||
(PFN_xrVoidFunction *)&s_xrGetD3D11GraphicsRequirementsKHR_fn))) {
|
||||
s_xrGetD3D11GraphicsRequirementsKHR_fn = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
s_xrGetD3D11GraphicsRequirementsKHR_fn(instance, system_id, &gpu_requirements);
|
||||
|
|
Loading…
Reference in New Issue