Browse Source

clean up _pfnTrackMouseEvent (CMU reported crash)

David Rose 23 years ago
parent
commit
8db75fced0

+ 13 - 0
panda/src/windisplay/winGraphicsPipe.cxx

@@ -28,6 +28,15 @@ TypeHandle WinGraphicsPipe::_type_handle;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 WinGraphicsPipe::
 WinGraphicsPipe::
 WinGraphicsPipe() {
 WinGraphicsPipe() {
+  // these fns arent defined on win95, so get dynamic ptrs to them
+  // to avoid ugly DLL loader failures on w95
+  _pfnTrackMouseEvent = NULL;
+
+  _hUser32 = (HINSTANCE)LoadLibrary("user32.dll");
+  if (_hUser32 != NULL) {
+    _pfnTrackMouseEvent = 
+      (PFN_TRACKMOUSEEVENT)GetProcAddress(_hUser32, "TrackMouseEvent");
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -37,4 +46,8 @@ WinGraphicsPipe() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 WinGraphicsPipe::
 WinGraphicsPipe::
 ~WinGraphicsPipe() {
 ~WinGraphicsPipe() {
+  if (_hUser32 != NULL) {
+    FreeLibrary(_hUser32);
+    _hUser32 = NULL;
+  }
 }
 }

+ 7 - 0
panda/src/windisplay/winGraphicsPipe.h

@@ -21,6 +21,7 @@
 
 
 #include "pandabase.h"
 #include "pandabase.h"
 #include "graphicsPipe.h"
 #include "graphicsPipe.h"
+#include "winGraphicsWindow.h"
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : WinGraphicsPipe
 //       Class : WinGraphicsPipe
@@ -40,6 +41,10 @@ public:
   WinGraphicsPipe();
   WinGraphicsPipe();
   virtual ~WinGraphicsPipe();
   virtual ~WinGraphicsPipe();
 
 
+private:
+  HINSTANCE _hUser32;
+  typedef BOOL (WINAPI *PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT);
+  PFN_TRACKMOUSEEVENT _pfnTrackMouseEvent;
 
 
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {
@@ -57,6 +62,8 @@ public:
 
 
 private:
 private:
   static TypeHandle _type_handle;
   static TypeHandle _type_handle;
+
+  friend class WinGraphicsWindow;
 };
 };
 
 
 #include "winGraphicsPipe.I"
 #include "winGraphicsPipe.I"

+ 5 - 18
panda/src/windisplay/winGraphicsWindow.cxx

@@ -29,9 +29,6 @@
 
 
 TypeHandle WinGraphicsWindow::_type_handle;
 TypeHandle WinGraphicsWindow::_type_handle;
 
 
-bool WinGraphicsWindow::_got_dynamic_fns = false;
-WinGraphicsWindow::PFN_TRACKMOUSEEVENT WinGraphicsWindow::_pfnTrackMouseEvent = NULL;
-
 bool WinGraphicsWindow::_loaded_custom_cursor;
 bool WinGraphicsWindow::_loaded_custom_cursor;
 HCURSOR WinGraphicsWindow::_mouse_cursor;
 HCURSOR WinGraphicsWindow::_mouse_cursor;
 const char * const WinGraphicsWindow::_window_class_name = "WinGraphicsWindow";
 const char * const WinGraphicsWindow::_window_class_name = "WinGraphicsWindow";
@@ -72,19 +69,6 @@ WinGraphicsWindow(GraphicsPipe *pipe) :
   _tracking_mouse_leaving = false;
   _tracking_mouse_leaving = false;
   _maximized = false;
   _maximized = false;
   memset(_keyboard_state, 0, sizeof(BYTE) * num_virtual_keys);
   memset(_keyboard_state, 0, sizeof(BYTE) * num_virtual_keys);
-
-  if (!_got_dynamic_fns) {
-    // these fns arent defined on win95, so get dynamic ptrs to them
-    // to avoid ugly DLL loader failures on w95
-    HINSTANCE hUser32 = (HINSTANCE)LoadLibrary("user32.dll");
-    if (hUser32) {
-      _pfnTrackMouseEvent = 
-        (PFN_TRACKMOUSEEVENT)GetProcAddress(hUser32, "TrackMouseEvent");
-      FreeLibrary(hUser32);
-    }
-
-    _got_dynamic_fns = true;
-  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -628,7 +612,10 @@ track_mouse_leaving(HWND hwnd) {
   // 3.0+) which emulates TrackMouseEvent on w95, but that requires
   // 3.0+) which emulates TrackMouseEvent on w95, but that requires
   // another 500K of memory to hold that DLL, which is lame just to
   // another 500K of memory to hold that DLL, which is lame just to
   // support w95, which probably has other issues anyway
   // support w95, which probably has other issues anyway
-  if (_pfnTrackMouseEvent != NULL) {
+  WinGraphicsPipe *winpipe;
+  DCAST_INTO_V(winpipe, _pipe);
+
+  if (winpipe->_pfnTrackMouseEvent != NULL) {
     TRACKMOUSEEVENT tme = {
     TRACKMOUSEEVENT tme = {
       sizeof(TRACKMOUSEEVENT),
       sizeof(TRACKMOUSEEVENT),
       TME_LEAVE,
       TME_LEAVE,
@@ -637,7 +624,7 @@ track_mouse_leaving(HWND hwnd) {
     };
     };
 
 
     // tell win32 to post WM_MOUSELEAVE msgs
     // tell win32 to post WM_MOUSELEAVE msgs
-    BOOL bSucceeded = _pfnTrackMouseEvent(&tme);  
+    BOOL bSucceeded = winpipe->_pfnTrackMouseEvent(&tme);  
     
     
     if ((!bSucceeded) && windisplay_cat.is_debug()) {
     if ((!bSucceeded) && windisplay_cat.is_debug()) {
       windisplay_cat.debug()
       windisplay_cat.debug()

+ 0 - 4
panda/src/windisplay/winGraphicsWindow.h

@@ -107,10 +107,6 @@ private:
   bool _maximized;
   bool _maximized;
   DEVMODE _fullscreen_display_mode;
   DEVMODE _fullscreen_display_mode;
 
 
-  static bool _got_dynamic_fns;
-  typedef BOOL (WINAPI *PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT);
-  static PFN_TRACKMOUSEEVENT _pfnTrackMouseEvent;
-
   // This is used to remember the state of the keyboard when keyboard
   // This is used to remember the state of the keyboard when keyboard
   // focus is lost.
   // focus is lost.
   static const int num_virtual_keys = 256;
   static const int num_virtual_keys = 256;