From 460ea9266738b9948f3a5abca973dc42a6050ebe Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 9 Jul 2009 14:52:05 +0000 Subject: [PATCH] Fix some issues on linux --- direct/src/plugin/p3dX11SplashWindow.cxx | 28 ++++++++++++++++-------- direct/src/plugin/p3dX11SplashWindow.h | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/direct/src/plugin/p3dX11SplashWindow.cxx b/direct/src/plugin/p3dX11SplashWindow.cxx index 96ec6a5948..cf2d899e74 100755 --- a/direct/src/plugin/p3dX11SplashWindow.cxx +++ b/direct/src/plugin/p3dX11SplashWindow.cxx @@ -16,6 +16,14 @@ #ifdef HAVE_X11 +#include + +// Sleeps for a millisecond. +#define MILLISLEEP() \ + timespec ts; \ + ts.tv_sec = 0; ts.tv_nsec = 1000000; \ + nanosleep(&ts, NULL); + //////////////////////////////////////////////////////////////////// // Function: P3DX11SplashWindow::Constructor // Access: Public @@ -72,8 +80,7 @@ set_image_filename(const string &image_filename, } RELEASE_LOCK(_install_lock); - // Post a silly message to spin the message loop. - //PostThreadMessage(_thread_id, WM_USER, 0, 0); + MILLISLEEP(); if (!_thread_running && _thread_continue) { // The user must have closed the window. Let's shut down the @@ -97,8 +104,7 @@ set_install_label(const string &install_label) { } RELEASE_LOCK(_install_lock); - // Post a silly message to spin the message loop. - //PostThreadMessage(_thread_id, WM_USER, 0, 0); + MILLISLEEP(); if (!_thread_running && _thread_continue) { // The user must have closed the window. Let's shut down the @@ -120,8 +126,7 @@ set_install_progress(double install_progress) { _install_progress = install_progress; RELEASE_LOCK(_install_lock); - // Post a silly message to spin the message loop. - //PostThreadMessage(_thread_id, WM_USER, 0, 0); + MILLISLEEP(); if (!_thread_running && _thread_continue) { // The user must have closed the window. Let's shut down the @@ -153,8 +158,7 @@ start_thread() { void P3DX11SplashWindow:: stop_thread() { _thread_continue = false; - // Post a silly message to spin the message loop. - //PostThreadMessage(_thread_id, WM_USER, 0, 0); + MILLISLEEP(); JOIN_THREAD(_thread); } @@ -231,8 +235,10 @@ make_window() { Window parent = 0; _display = (Display*) _wparams.get_parent_window()._xdisplay; + _own_display = false; if (_display == 0) { _display = XOpenDisplay(NULL); + _own_display = true; } _screen = DefaultScreen(_display); @@ -287,12 +293,16 @@ setup_gc() { //////////////////////////////////////////////////////////////////// void P3DX11SplashWindow:: close_window() { + if (_graphics_context != None) { + XFreeGC(_display, _graphics_context); + } + if (_window != None) { XDestroyWindow(_display, _window); _window = None; } - if (_display != None) { + if (_display != None && _own_display) { XCloseDisplay(_display); _display = None; } diff --git a/direct/src/plugin/p3dX11SplashWindow.h b/direct/src/plugin/p3dX11SplashWindow.h index 5d1f496003..6970ed3cb3 100755 --- a/direct/src/plugin/p3dX11SplashWindow.h +++ b/direct/src/plugin/p3dX11SplashWindow.h @@ -55,6 +55,7 @@ private: void close_window(); private: + bool _own_display; bool _got_install; bool _image_filename_changed; string _image_filename;