David Rose 16 лет назад
Родитель
Сommit
42704cd357

+ 4 - 3
direct/src/plugin/p3dInstance.cxx

@@ -255,7 +255,8 @@ feed_url_stream(int unique_id,
                 size_t this_data_size) {
                 size_t this_data_size) {
   Downloads::iterator di = _downloads.find(unique_id);
   Downloads::iterator di = _downloads.find(unique_id);
   if (di == _downloads.end()) {
   if (di == _downloads.end()) {
-    nout << "Unexpected feed_url_stream for " << unique_id << "\n";
+    nout << "Unexpected feed_url_stream for " << unique_id << "\n"
+         << flush;
     // Don't know this request.
     // Don't know this request.
     return false;
     return false;
   }
   }
@@ -267,7 +268,7 @@ feed_url_stream(int unique_id,
 
 
   if (!download_ok || download->get_download_finished()) {
   if (!download_ok || download->get_download_finished()) {
     // All done.
     // All done.
-    nout << "completed download " << unique_id << "\n";
+    nout << "completed download " << unique_id << "\n" << flush;
     _downloads.erase(di);
     _downloads.erase(di);
     delete download;
     delete download;
   }
   }
@@ -313,7 +314,7 @@ start_download(P3DDownload *download) {
   assert(inserted);
   assert(inserted);
 
 
   nout << "beginning download " << download_id << ": " << download->get_url()
   nout << "beginning download " << download_id << ": " << download->get_url()
-       << "\n";
+       << "\n" << flush;
 
 
   P3D_request *request = new P3D_request;
   P3D_request *request = new P3D_request;
   request->_instance = this;
   request->_instance = this;

+ 5 - 5
direct/src/plugin/p3dInstanceManager.cxx

@@ -35,7 +35,6 @@ P3DInstanceManager *P3DInstanceManager::_global_ptr;
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 P3DInstanceManager::
 P3DInstanceManager::
 P3DInstanceManager() {
 P3DInstanceManager() {
-  nout << "creating instance manager\n";
   _is_initialized = false;
   _is_initialized = false;
   _unique_session_index = 0;
   _unique_session_index = 0;
 
 
@@ -93,10 +92,10 @@ initialize() {
   _platform = P3D_PLUGIN_PLATFORM;
   _platform = P3D_PLUGIN_PLATFORM;
 
 
   nout << "_root_dir = " << _root_dir << ", download = " 
   nout << "_root_dir = " << _root_dir << ", download = " 
-       << _download_url << "\n";
+       << _download_url << "\n" << flush;
 
 
   if (_root_dir.empty()) {
   if (_root_dir.empty()) {
-    nout << "Could not find root directory.\n";
+    nout << "Could not find root directory.\n" << flush;
     return false;
     return false;
   }
   }
 
 
@@ -131,7 +130,7 @@ bool P3DInstanceManager::
 start_instance(P3DInstance *inst, const string &p3d_filename,
 start_instance(P3DInstance *inst, const string &p3d_filename,
                const P3D_token tokens[], size_t num_tokens) {
                const P3D_token tokens[], size_t num_tokens) {
   if (inst->is_started()) {
   if (inst->is_started()) {
-    nout << "Instance started twice: " << inst << "\n";
+    nout << "Instance started twice: " << inst << "\n" << flush;
     return false;
     return false;
   }
   }
   inst->set_fparams(P3DFileParams(p3d_filename, tokens, num_tokens));
   inst->set_fparams(P3DFileParams(p3d_filename, tokens, num_tokens));
@@ -159,6 +158,7 @@ start_instance(P3DInstance *inst, const string &p3d_filename,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void P3DInstanceManager::
 void P3DInstanceManager::
 finish_instance(P3DInstance *inst) {
 finish_instance(P3DInstance *inst) {
+  nout << "finish_instance(" << inst << ")\n" << flush;
   Instances::iterator ii;
   Instances::iterator ii;
   ii = _instances.find(inst);
   ii = _instances.find(inst);
   assert(ii != _instances.end());
   assert(ii != _instances.end());
@@ -541,7 +541,7 @@ find_root_dir() const {
   }
   }
 
 
   // Couldn't find a directory.  Bail.
   // Couldn't find a directory.  Bail.
-  nout << "Couldn't find a root directory.\n";
+  nout << "Couldn't find a root directory.\n" << flush;
   return string();
   return string();
 
 
 #else  // _WIN32
 #else  // _WIN32

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

@@ -86,13 +86,16 @@ P3DSession::
 
 
     // Also close the pipe, to help underscore the point.
     // Also close the pipe, to help underscore the point.
     _pipe_write.close();
     _pipe_write.close();
-    _pipe_read.close();
+
+    // Closing _pipe_read before the thread has stopped can result in
+    // a hang.  Don't need to close it yet.
+    //  _pipe_read.close();
 
 
 #ifdef _WIN32
 #ifdef _WIN32
     // Now give the process a chance to terminate itself cleanly.
     // Now give the process a chance to terminate itself cleanly.
     if (WaitForSingleObject(_p3dpython_handle, 2000) == WAIT_TIMEOUT) {
     if (WaitForSingleObject(_p3dpython_handle, 2000) == WAIT_TIMEOUT) {
       // It didn't shut down cleanly, so kill it the hard way.
       // It didn't shut down cleanly, so kill it the hard way.
-      nout << "Terminating process.\n";
+      nout << "Terminating process.\n" << flush;
       TerminateProcess(_p3dpython_handle, 2);
       TerminateProcess(_p3dpython_handle, 2);
     }
     }
 
 
@@ -298,18 +301,18 @@ start_p3dpython() {
 #endif
 #endif
 
 
   if (!started_p3dpython) {
   if (!started_p3dpython) {
-    nout << "Failed to create process.\n";
+    nout << "Failed to create process.\n" << flush;
     return;
     return;
   }
   }
   _p3dpython_running = true;
   _p3dpython_running = true;
 
 
-  nout << "Created child process\n";
+  nout << "Created child process\n" << flush;
 
 
   if (!_pipe_read) {
   if (!_pipe_read) {
-    nout << "unable to open read pipe\n";
+    nout << "unable to open read pipe\n" << flush;
   }
   }
   if (!_pipe_write) {
   if (!_pipe_write) {
-    nout << "unable to open write pipe\n";
+    nout << "unable to open write pipe\n" << flush;
   }
   }
   
   
   spawn_read_thread();
   spawn_read_thread();
@@ -366,7 +369,6 @@ join_read_thread() {
     return;
     return;
   }
   }
 
 
-  nout << "session waiting for thread\n";
   _read_thread_continue = false;
   _read_thread_continue = false;
   _pipe_read.close();
   _pipe_read.close();
   
   
@@ -379,7 +381,6 @@ join_read_thread() {
   void *return_val;
   void *return_val;
   pthread_join(_read_thread, &return_val);
   pthread_join(_read_thread, &return_val);
 #endif
 #endif
-  nout << "session done waiting for thread\n";
 
 
   _started_read_thread = false;
   _started_read_thread = false;
 }
 }
@@ -391,20 +392,20 @@ join_read_thread() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void P3DSession::
 void P3DSession::
 rt_thread_run() {
 rt_thread_run() {
-  nout << "session thread reading.\n";
+  nout << "session thread reading.\n" << flush;
   while (_read_thread_continue) {
   while (_read_thread_continue) {
     TiXmlDocument *doc = new TiXmlDocument;
     TiXmlDocument *doc = new TiXmlDocument;
 
 
     _pipe_read >> *doc;
     _pipe_read >> *doc;
     if (!_pipe_read || _pipe_read.eof()) {
     if (!_pipe_read || _pipe_read.eof()) {
       // Some error on reading.  Abort.
       // Some error on reading.  Abort.
-      nout << "Error on session reading.\n";
+      nout << "Error on session reading.\n" << flush;
       rt_terminate();
       rt_terminate();
       return;
       return;
     }
     }
 
 
     // Successfully read an XML document.
     // Successfully read an XML document.
-    nout << "Session got request: " << *doc << "\n";
+    nout << "Session got request: " << *doc << "\n" << flush;
 
 
     // TODO: feed the request up to the parent.
     // TODO: feed the request up to the parent.
     delete doc;
     delete doc;
@@ -486,7 +487,7 @@ win_create_process(const string &program, const string &start_dir,
 
 
   // Create the pipe to the process.
   // Create the pipe to the process.
   if (!CreatePipe(&r_to, &w_to, NULL, 0)) {
   if (!CreatePipe(&r_to, &w_to, NULL, 0)) {
-    nout << "failed to create pipe\n";
+    nout << "failed to create pipe\n" << flush;
   } else {
   } else {
     // Make sure the right end of the pipe is inheritable.
     // Make sure the right end of the pipe is inheritable.
     SetHandleInformation(r_to, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     SetHandleInformation(r_to, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
@@ -495,7 +496,7 @@ win_create_process(const string &program, const string &start_dir,
 
 
   // Create the pipe from the process.
   // Create the pipe from the process.
   if (!CreatePipe(&r_from, &w_from, NULL, 0)) {
   if (!CreatePipe(&r_from, &w_from, NULL, 0)) {
-    nout << "failed to create pipe\n";
+    nout << "failed to create pipe\n" << flush;
   } else { 
   } else { 
     // Make sure the right end of the pipe is inheritable.
     // Make sure the right end of the pipe is inheritable.
     SetHandleInformation(w_from, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     SetHandleInformation(w_from, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
@@ -515,7 +516,7 @@ win_create_process(const string &program, const string &start_dir,
       error_handle = handle;
       error_handle = handle;
       SetHandleInformation(error_handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
       SetHandleInformation(error_handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
     } else {
     } else {
-      nout << "Unable to open " << output_filename << "\n";
+      nout << "Unable to open " << output_filename << "\n" << flush;
     }
     }
   }
   }
 
 
@@ -614,7 +615,7 @@ posix_create_process(const string &program, const string &start_dir,
       int logfile_fd = open(output_filename.c_str(), 
       int logfile_fd = open(output_filename.c_str(), 
                             O_WRONLY | O_CREAT | O_TRUNC, 0666);
                             O_WRONLY | O_CREAT | O_TRUNC, 0666);
       if (logfile_fd < 0) {
       if (logfile_fd < 0) {
-        nout << "Unable to open " << output_filename << "\n";
+        nout << "Unable to open " << output_filename << "\n" << flush;
       } else {
       } else {
         dup2(logfile_fd, STDERR_FILENO);
         dup2(logfile_fd, STDERR_FILENO);
         close(logfile_fd);
         close(logfile_fd);
@@ -629,7 +630,7 @@ posix_create_process(const string &program, const string &start_dir,
     close(from_fd[0]);
     close(from_fd[0]);
 
 
     if (chdir(start_dir.c_str()) < 0) {
     if (chdir(start_dir.c_str()) < 0) {
-      nout << "Could not chdir to " << start_dir << "\n";
+      nout << "Could not chdir to " << start_dir << "\n" << flush;
       _exit(1);
       _exit(1);
     }
     }
 
 
@@ -645,7 +646,7 @@ posix_create_process(const string &program, const string &start_dir,
     ptrs.push_back((char *)NULL);
     ptrs.push_back((char *)NULL);
     
     
     execle(program.c_str(), program.c_str(), (char *)0, &ptrs[0]);
     execle(program.c_str(), program.c_str(), (char *)0, &ptrs[0]);
-    nout << "Failed to exec " << program << "\n";
+    nout << "Failed to exec " << program << "\n" << flush;
     _exit(1);
     _exit(1);
   }
   }
 
 

+ 8 - 3
direct/src/plugin_npapi/ppInstance.cxx

@@ -68,7 +68,7 @@ PPInstance(NPMIMEType pluginType, NPP instance, uint16 mode,
 PPInstance::
 PPInstance::
 ~PPInstance() {
 ~PPInstance() {
   logfile
   logfile
-    << "destructing " << this << "\n" << flush;
+    << "destructing " << this << ", " << _p3d_inst << "\n" << flush;
 
 
   if (_p3d_inst != NULL) {
   if (_p3d_inst != NULL) {
     P3D_instance_finish(_p3d_inst);
     P3D_instance_finish(_p3d_inst);
@@ -124,6 +124,7 @@ new_stream(NPMIMEType type, NPStream *stream, bool seekable, uint16 *stype) {
     if (!_started_instance_data) {
     if (!_started_instance_data) {
       stream->notifyData = new PPDownloadRequest(PPDownloadRequest::RT_instance_data);
       stream->notifyData = new PPDownloadRequest(PPDownloadRequest::RT_instance_data);
       *stype = NP_ASFILEONLY;
       *stype = NP_ASFILEONLY;
+      _started_instance_data = true;
       return NPERR_NO_ERROR;
       return NPERR_NO_ERROR;
     }
     }
 
 
@@ -433,8 +434,12 @@ send_window() {
   parent_window._hwnd = (HWND)(_window.window);
   parent_window._hwnd = (HWND)(_window.window);
 #endif
 #endif
 
 
+  // Actually, we set up the window starting at (0, 0), instead of
+  // whatever Mozilla tells us, because the window handle we get is a
+  // specially created window that is already aligned to where we want
+  // our window to be.
   P3D_instance_setup_window
   P3D_instance_setup_window
-    (_p3d_inst, P3D_WT_toplevel,
-     _window.x, _window.y, _window.width, _window.height,
+    (_p3d_inst, P3D_WT_embedded,
+     0, 0, _window.width, _window.height,
      parent_window);
      parent_window);
 }
 }

+ 4 - 0
direct/src/plugin_npapi/startup.cxx

@@ -213,8 +213,12 @@ NP_Shutdown(void) {
   RELEASE_LOCK(_timer_lock);
   RELEASE_LOCK(_timer_lock);
   DESTROY_LOCK(_timer_lock);
   DESTROY_LOCK(_timer_lock);
 
 
+  logfile << "unloading plugin\n" << flush;
+
   unload_plugin();
   unload_plugin();
 
 
+  logfile << "done shutdown\n" << flush;
+
   // Not clear whether there's a return value or not.  Some versions
   // Not clear whether there's a return value or not.  Some versions
   // of the API have different opinions on this.
   // of the API have different opinions on this.
   return NPERR_NO_ERROR;
   return NPERR_NO_ERROR;

+ 20 - 11
direct/src/showbase/VFSImporter.py

@@ -101,7 +101,7 @@ class VFSLoader:
         
         
         code = self._read_code()
         code = self._read_code()
         if not code:
         if not code:
-            raise ImportError
+            raise ImportError, 'No Python code in %s' % (fullname)
         
         
         mod = sys.modules.setdefault(fullname, new.module(fullname))
         mod = sys.modules.setdefault(fullname, new.module(fullname))
         mod.__file__ = self.filename.cStr()
         mod.__file__ = self.filename.cStr()
@@ -128,7 +128,7 @@ class VFSLoader:
         
         
     def _read_source(self):
     def _read_source(self):
         """ Returns the Python source for this file, if it is
         """ Returns the Python source for this file, if it is
-        available, or None if it is not. """
+        available, or None if it is not.  May raise IOError. """
         
         
         if self.fileType == FTPythonCompiled or \
         if self.fileType == FTPythonCompiled or \
            self.fileType == FTCompiledModule:
            self.fileType == FTCompiledModule:
@@ -136,10 +136,7 @@ class VFSLoader:
         
         
         filename = Filename(self.filename)
         filename = Filename(self.filename)
         filename.setExtension('py')
         filename.setExtension('py')
-        try:
-            file = open(filename, 'rU')
-        except IOError:
-            return None
+        file = open(filename, 'rU')
         return file.read()
         return file.read()
 
 
     def _import_compiled_module(self, fullname):
     def _import_compiled_module(self, fullname):
@@ -179,14 +176,16 @@ class VFSLoader:
 
 
     def _read_code(self):
     def _read_code(self):
         """ Returns the Python compiled code object for this file, if
         """ Returns the Python compiled code object for this file, if
-        it is available, or None if it is not. """
+        it is available, or None if it is not.  May raise IOError,
+        ValueError, SyntaxError, or a number of other errors generated
+        by the low-level system. """
 
 
         if self.fileType == FTPythonCompiled:
         if self.fileType == FTPythonCompiled:
             # It's a pyc file; just read it directly.
             # It's a pyc file; just read it directly.
             pycVfile = vfs.getFile(self.filename, False)
             pycVfile = vfs.getFile(self.filename, False)
             if pycVfile:
             if pycVfile:
                 return self._loadPyc(pycVfile, None)
                 return self._loadPyc(pycVfile, None)
-            return None
+            raise IOError, 'Could not read %s' % (self.filename)
 
 
         elif self.fileType == FTCompiledModule:
         elif self.fileType == FTCompiledModule:
             return None
             return None
@@ -205,7 +204,10 @@ class VFSLoader:
 
 
         code = None
         code = None
         if t_pyc and t_pyc >= self.timestamp:
         if t_pyc and t_pyc >= self.timestamp:
-            code = self._loadPyc(pycVfile, self.timestamp)
+            try:
+                code = self._loadPyc(pycVfile, self.timestamp)
+            except ValueError:
+                code = None
 
 
         if not code:
         if not code:
             source = self._read_source()
             source = self._read_source()
@@ -216,20 +218,27 @@ class VFSLoader:
         return code
         return code
 
 
     def _loadPyc(self, vfile, timestamp):
     def _loadPyc(self, vfile, timestamp):
-        """ Reads and returns the marshal data from a .pyc file. """
+        """ Reads and returns the marshal data from a .pyc file.
+        Raises ValueError if there is a problem. """
+        
         code = None
         code = None
         f = open(vfile, 'rb')
         f = open(vfile, 'rb')
         if f.read(4) == imp.get_magic():
         if f.read(4) == imp.get_magic():
             t = struct.unpack('<I', f.read(4))[0]
             t = struct.unpack('<I', f.read(4))[0]
             if not timestamp or t == timestamp:
             if not timestamp or t == timestamp:
                 code = marshal.loads(f.read())
                 code = marshal.loads(f.read())
+            else:
+                raise ValueError, 'Timestamp wrong on %s' % (vfile)
+        else:
+            raise ValueError, 'Bad magic number in %s' % (vfile)
         f.close()
         f.close()
         return code
         return code
         
         
 
 
     def _compile(self, filename, source):
     def _compile(self, filename, source):
         """ Compiles the Python source code to a code object and
         """ Compiles the Python source code to a code object and
-        attempts to write it to an appropriate .pyc file. """
+        attempts to write it to an appropriate .pyc file.  May raise
+        SyntaxError or other errors generated by the compiler. """
         
         
         if source and source[-1] != '\n':
         if source and source[-1] != '\n':
             source = source + '\n'
             source = source + '\n'