diff options
author | Brian Paul <[email protected]> | 2016-05-20 14:24:59 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2016-06-30 12:43:50 -0600 |
commit | 395ee18bacf04a9aac6996bca8364bde24f2f3b0 (patch) | |
tree | 8b7c14227438a45ddbf86a9c2b7edcaaa357c06b /src/gallium | |
parent | 128feef40e81b320af59edc7a2fcf6b2ad8d2b8d (diff) |
st/wgl: add a stw_device::initialized field
Set when the stw_dev object's initialization is completed. We test
for this in the window callback function to avoid potential crashes
on start-up in multi-threaded applications.
Reviewed-by: José Fonseca <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/state_trackers/wgl/stw_device.c | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/wgl/stw_device.h | 2 | ||||
-rw-r--r-- | src/gallium/state_trackers/wgl/stw_framebuffer.c | 55 |
3 files changed, 35 insertions, 24 deletions
diff --git a/src/gallium/state_trackers/wgl/stw_device.c b/src/gallium/state_trackers/wgl/stw_device.c index 287b937afe5..b57f96f2e87 100644 --- a/src/gallium/state_trackers/wgl/stw_device.c +++ b/src/gallium/state_trackers/wgl/stw_device.c @@ -116,6 +116,8 @@ stw_init(const struct stw_winsys *stw_winsys) stw_pixelformat_init(); + stw_dev->initialized = true; + return TRUE; error1: diff --git a/src/gallium/state_trackers/wgl/stw_device.h b/src/gallium/state_trackers/wgl/stw_device.h index 15d66a24e5d..ecf212d7cb6 100644 --- a/src/gallium/state_trackers/wgl/stw_device.h +++ b/src/gallium/state_trackers/wgl/stw_device.h @@ -77,6 +77,8 @@ struct stw_device #ifdef DEBUG unsigned long memdbg_no; #endif + + bool initialized; }; diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c index 12636156a5e..d770adb2a55 100644 --- a/src/gallium/state_trackers/wgl/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c @@ -203,32 +203,39 @@ stw_call_window_proc(int nCode, WPARAM wParam, LPARAM lParam) if (nCode < 0 || !stw_dev) return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); - if (pParams->message == WM_WINDOWPOSCHANGED) { - /* We handle WM_WINDOWPOSCHANGED instead of WM_SIZE because according to - * http://blogs.msdn.com/oldnewthing/archive/2008/01/15/7113860.aspx - * WM_SIZE is generated from WM_WINDOWPOSCHANGED by DefWindowProc so it - * can be masked out by the application. - */ - LPWINDOWPOS lpWindowPos = (LPWINDOWPOS)pParams->lParam; - if ((lpWindowPos->flags & SWP_SHOWWINDOW) || - !(lpWindowPos->flags & SWP_NOMOVE) || - !(lpWindowPos->flags & SWP_NOSIZE)) { - fb = stw_framebuffer_from_hwnd( pParams->hwnd ); - if (fb) { - /* Size in WINDOWPOS includes the window frame, so get the size - * of the client area via GetClientRect. - */ - stw_framebuffer_get_size(fb); - stw_framebuffer_unlock(fb); + /* We check that the stw_dev object is initialized before we try to do + * anything with it. Otherwise, in multi-threaded programs there's a + * chance of executing this code before the stw_dev object is fully + * initialized. + */ + if (stw_dev && stw_dev->initialized) { + if (pParams->message == WM_WINDOWPOSCHANGED) { + /* We handle WM_WINDOWPOSCHANGED instead of WM_SIZE because according + * to http://blogs.msdn.com/oldnewthing/archive/2008/01/15/7113860.aspx + * WM_SIZE is generated from WM_WINDOWPOSCHANGED by DefWindowProc so it + * can be masked out by the application. + */ + LPWINDOWPOS lpWindowPos = (LPWINDOWPOS)pParams->lParam; + if ((lpWindowPos->flags & SWP_SHOWWINDOW) || + !(lpWindowPos->flags & SWP_NOMOVE) || + !(lpWindowPos->flags & SWP_NOSIZE)) { + fb = stw_framebuffer_from_hwnd( pParams->hwnd ); + if (fb) { + /* Size in WINDOWPOS includes the window frame, so get the size + * of the client area via GetClientRect. + */ + stw_framebuffer_get_size(fb); + stw_framebuffer_unlock(fb); + } } } - } - else if (pParams->message == WM_DESTROY) { - stw_lock_framebuffers(stw_dev); - fb = stw_framebuffer_from_hwnd_locked( pParams->hwnd ); - if (fb) - stw_framebuffer_release_locked(fb); - stw_unlock_framebuffers(stw_dev); + else if (pParams->message == WM_DESTROY) { + stw_lock_framebuffers(stw_dev); + fb = stw_framebuffer_from_hwnd_locked( pParams->hwnd ); + if (fb) + stw_framebuffer_release_locked(fb); + stw_unlock_framebuffers(stw_dev); + } } return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); |