changeset 6563:89ca2db487e3

RT-35263: Win: Crashing VM in a JavaFX 3D app reading and writing STL files Summary: Check if the window is still alive after handling a synthetic mouse ENTER event Reviewed-by: snorthov, fheidric
author Anthony Petrov <anthony.petrov@oracle.com>
date Wed, 26 Mar 2014 15:13:56 +0400
parents 14580ce9a75e
children 0f1a42edda54
files modules/graphics/src/main/native-glass/win/ViewContainer.cpp
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/win/ViewContainer.cpp	Wed Mar 26 09:39:16 2014 +0100
+++ b/modules/graphics/src/main/native-glass/win/ViewContainer.cpp	Wed Mar 26 15:13:56 2014 +0400
@@ -34,6 +34,7 @@
 #include "GlassDnD.h"
 #include "GlassInputTextInfo.h"
 #include "ManipulationEvents.h"
+#include "BaseWnd.h"
 
 #include "com_sun_glass_events_ViewEvent.h"
 #include "com_sun_glass_events_KeyEvent.h"
@@ -652,6 +653,12 @@
             // Mouse tracking will be canceled automatically upon receiving WM_MOUSELEAVE
             m_bTrackingMouse = TRUE;
         }
+
+        // Note that (ViewContainer*)this != (BaseWnd*)this. We could use
+        // dynamic_case<>() instead, but it would fail later if 'this' is
+        // already deleted. So we use FromHandle() which is safe.
+        const BaseWnd *origWnd = BaseWnd::FromHandle(hwnd);
+
         env->CallVoidMethod(GetView(), javaIDs.View.notifyMouse,
                 com_sun_glass_events_MouseEvent_ENTER,
                 com_sun_glass_events_MouseEvent_BUTTON_NONE,
@@ -659,7 +666,11 @@
                 jModifiers, JNI_FALSE, isSynthesized);
         CheckAndClearException(env);
 
-        if (!GetGlassView()) {
+        // At this point 'this' might have already been deleted if the app
+        // closed the window while processing the ENTER event. Hence the check:
+        if (!::IsWindow(hwnd) || BaseWnd::FromHandle(hwnd) != origWnd ||
+                !GetGlassView())
+        {
             return TRUE;
         }
     }