Browse Source

some windows issues

David Rose 16 years ago
parent
commit
92265c7134

+ 17 - 0
direct/src/plugin/p3dSession.cxx

@@ -279,7 +279,24 @@ command_and_response(TiXmlDocument *command) {
       return NULL;
       return NULL;
     }
     }
 
 
+#ifdef _WIN32
+    // Make sure we process the Windows event loop while we're
+    // waiting, or everything that depends on Windows messages--in
+    // particular, the CreateWindow() call within the subprocess--will
+    // starve, and we could end up with deadlock.
+
+    // A single PeekMessage() seems to be sufficient.
+    MSG msg;
+    PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE | PM_NOYIELD);
+
+    // We wait with a timeout, so we can go back and spin the event
+    // loop some more.
+    _response_ready.wait(0.1);
+#else  // _WIN32
+    
+    // On non-Windows platforms, we can just wait indefinitely.
     _response_ready.wait();
     _response_ready.wait();
+#endif  // _WIN32
   }
   }
   // When we exit the loop, we've found the desired response.
   // When we exit the loop, we've found the desired response.
 
 

+ 13 - 0
direct/src/plugin_npapi/ppInstance.I

@@ -23,3 +23,16 @@ inline NPP PPInstance::
 get_npp_instance() const {
 get_npp_instance() const {
   return _npp_instance;
   return _npp_instance;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPInstance::get_window
+//       Access: Public
+//  Description: Returns the current window parameters.
+////////////////////////////////////////////////////////////////////
+const NPWindow *PPInstance::
+get_window() const {
+  if (_got_window) {
+    return &_window;
+  }
+  return NULL;
+}

+ 1 - 0
direct/src/plugin_npapi/ppInstance.h

@@ -38,6 +38,7 @@ public:
 
 
   inline NPP get_npp_instance() const;
   inline NPP get_npp_instance() const;
 
 
+  inline const NPWindow *get_window() const;
   void set_window(NPWindow *window);
   void set_window(NPWindow *window);
   NPError new_stream(NPMIMEType type, NPStream *stream, 
   NPError new_stream(NPMIMEType type, NPStream *stream, 
                      bool seekable, uint16 *stype);
                      bool seekable, uint16 *stype);

+ 8 - 12
direct/src/plugin_npapi/startup.cxx

@@ -33,10 +33,6 @@ open_logfile() {
   }
   }
 }
 }
 
 
-#ifdef _WIN32
-DWORD main_thread_id = 0;
-#endif
-
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: handle_request_loop
 //     Function: handle_request_loop
@@ -103,7 +99,14 @@ request_ready(P3D_instance *instance) {
   // Since we might be in a sub-thread at this point, use a Windows
   // Since we might be in a sub-thread at this point, use a Windows
   // message to forward this event to the main thread.
   // message to forward this event to the main thread.
 
 
-  PostThreadMessage(main_thread_id, WM_USER, 0, 0);
+  // Get the window handle for the window associated with this
+  // instance.
+  PPInstance *inst = (PPInstance *)(instance->_user_data);
+  assert(inst != NULL);
+  const NPWindow *win = inst->get_window();
+  if (win != NULL) {
+    PostMessage((HWND)(win->window), WM_USER, 0, 0);
+  }
 
 
 #else
 #else
   // On Mac, we ignore this asynchronous event, and rely on detecting
   // On Mac, we ignore this asynchronous event, and rely on detecting
@@ -139,13 +142,6 @@ NP_Initialize(NPNetscapeFuncs *browserFuncs,
   open_logfile();
   open_logfile();
   logfile << "initializing\n" << flush;
   logfile << "initializing\n" << flush;
 
 
-#ifdef _WIN32
-  // Save the calling thread ID (i.e. the main thread) so we can post
-  // messages back to this thread when needed.
-  main_thread_id = GetCurrentThreadId();
-  logfile << "main thread = " << main_thread_id << "\n";
-#endif
-
   logfile << "browserFuncs = " << browserFuncs << "\n" << flush;
   logfile << "browserFuncs = " << browserFuncs << "\n" << flush;
 
 
   return NPERR_NO_ERROR;
   return NPERR_NO_ERROR;