From db28251d402cf415f44e93385bdfaf6de496974c Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 13 Nov 2009 01:20:52 +0000 Subject: [PATCH] fix onwindowattach/detach for mac --- panda/src/display/graphicsStateGuardian.cxx | 8 ++++- panda/src/display/subprocessWindow.cxx | 17 +++++++++++ panda/src/display/subprocessWindowBuffer.cxx | 14 ++++----- .../osxdisplay/osxGraphicsStateGuardian.cxx | 1 + panda/src/osxdisplay/osxGraphicsWindow.mm | 29 ++++++++++--------- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 941bb032b9..52ea351974 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -2385,11 +2385,17 @@ free_pointers() { //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: close_gsg() { + // Protect from multiple calls, and also inform any other functions + // not to try to create new stuff while we're going down. + if (_closing_gsg) { + return; + } + _closing_gsg = true; + if (display_cat.is_debug()) { display_cat.debug() << this << " close_gsg " << get_type() << "\n"; } - _closing_gsg = true; free_pointers(); // As tempting as it may be to try to release all the textures and diff --git a/panda/src/display/subprocessWindow.cxx b/panda/src/display/subprocessWindow.cxx index 2cc769e435..866cb621cf 100644 --- a/panda/src/display/subprocessWindow.cxx +++ b/panda/src/display/subprocessWindow.cxx @@ -345,6 +345,14 @@ internal_close_window() { _buffer = NULL; } + // Tell our parent window (if any) that we're no longer its child. + if (_window_handle != (WindowHandle *)NULL && + _parent_window_handle != (WindowHandle *)NULL) { + _parent_window_handle->detach_child(_window_handle); + } + + _window_handle = NULL; + _parent_window_handle = NULL; _is_valid = false; } @@ -395,6 +403,7 @@ internal_open_window() { } } } + _parent_window_handle = window_handle; if (_filename.empty()) { _is_valid = false; @@ -422,6 +431,14 @@ internal_open_window() { << "SubprocessWindow reading " << _filename << "\n"; } + // Create a WindowHandle for ourselves + _window_handle = NativeWindowHandle::make_subprocess(_filename); + + // And tell our parent window that we're now its child. + if (_parent_window_handle != (WindowHandle *)NULL) { + _parent_window_handle->attach_child(_window_handle); + } + return true; } diff --git a/panda/src/display/subprocessWindowBuffer.cxx b/panda/src/display/subprocessWindowBuffer.cxx index a2782f86d0..e5274ac5a1 100644 --- a/panda/src/display/subprocessWindowBuffer.cxx +++ b/panda/src/display/subprocessWindowBuffer.cxx @@ -157,11 +157,7 @@ destroy_buffer(int fd, size_t mmap_size, const string &filename, buffer->~SubprocessWindowBuffer(); close_buffer(fd, mmap_size, filename, buffer); - // This isn't really necessary, since our child process should have - // unlinked it; but we do it anyway just for good measure (for - // instance, in case the child process never got started). I - // suppose there is some risk that we will accidentally delete - // someone else's file this way, but the risk is small. + // Now we can unlink the file. unlink(filename.c_str()); } @@ -243,7 +239,10 @@ open_buffer(int &fd, size_t &mmap_size, const string &filename) { // Now that we've successfully opened and mapped the file, we can // safely delete it from the file system. - unlink(filename.c_str()); + + // Actually, unlinking it now prevents us from detaching and + // reattaching to the same file later. Boo. + // unlink(filename.c_str()); SubprocessWindowBuffer *buffer = (SubprocessWindowBuffer *)shared_mem; assert(buffer->_mmap_size == mmap_size); @@ -263,9 +262,6 @@ close_buffer(int fd, size_t mmap_size, const string &filename, SubprocessWindowBuffer *buffer) { munmap((void *)buffer, mmap_size); close(fd); - - // Guess we shouldn't unlink() the file here, since we already did - // in open_buffer(). } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/osxdisplay/osxGraphicsStateGuardian.cxx b/panda/src/osxdisplay/osxGraphicsStateGuardian.cxx index 8a006ea3d3..9a0381d3bc 100644 --- a/panda/src/osxdisplay/osxGraphicsStateGuardian.cxx +++ b/panda/src/osxdisplay/osxGraphicsStateGuardian.cxx @@ -75,6 +75,7 @@ osxGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe, osxGraphicsStateGuardian:: ~osxGraphicsStateGuardian() { if (_aglcontext != (AGLContext)NULL) { + aglSetCurrentContext(NULL); aglDestroyContext(_aglcontext); report_agl_error("aglDestroyContext"); _aglcontext = (AGLContext)NULL; diff --git a/panda/src/osxdisplay/osxGraphicsWindow.mm b/panda/src/osxdisplay/osxGraphicsWindow.mm index 8d834ac6d2..e537286ecb 100644 --- a/panda/src/osxdisplay/osxGraphicsWindow.mm +++ b/panda/src/osxdisplay/osxGraphicsWindow.mm @@ -403,9 +403,16 @@ do_resize() { << " " << viewRect.size.height << "\n"; } - // ping gl - aglUpdateContext(aglGetCurrentContext()); - report_agl_error("aglUpdateContext .. This is a Resize.."); + AGLContext context = get_gsg_context(); + if (context != (AGLContext)NULL) { + // ping gl + if (!aglSetCurrentContext(context)) { + report_agl_error("aglSetCurrentContext"); + } + aglUpdateContext(context); + report_agl_error("aglUpdateContext .. This is a Resize.."); + } + if (osxdisplay_cat.is_debug()) { osxdisplay_cat.debug() << "Resize Complete.....\n"; @@ -849,23 +856,19 @@ begin_frame(FrameMode mode, Thread *current_thread) { if (_is_fullscreen) { aglSetFullScreen(get_gsg_context(),0,0,0,0); report_agl_error ("aglSetFullScreen"); - - if (!aglSetCurrentContext(get_gsg_context())) { - report_agl_error ("aglSetCurrentContext"); - } - + } else { if (full_screen_window != NULL) { return false; } - if (!aglSetDrawable (get_gsg_context(), GetWindowPort (_osx_window))) { + if (!aglSetDrawable(get_gsg_context(), GetWindowPort (_osx_window))) { report_agl_error("aglSetDrawable"); } - - if (!aglSetCurrentContext(get_gsg_context())) { - report_agl_error ("aglSetCurrentContext"); - } + } + + if (!aglSetCurrentContext(get_gsg_context())) { + report_agl_error ("aglSetCurrentContext"); } _gsg->reset_if_new();