diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index 678b6f2d58..67d7697c73 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -508,7 +508,9 @@ add_raw_request(TiXmlDocument *doc) { // Tell the world we've got a new request. P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); inst_mgr->signal_request_ready(this); - _session->signal_request_ready(this); + if (_session != NULL) { + _session->signal_request_ready(this); + } } //////////////////////////////////////////////////////////////////// @@ -881,13 +883,36 @@ make_xml() { } //////////////////////////////////////////////////////////////////// -// Function: P3DInstance::splash_button_clicked +// Function: P3DInstance::splash_button_clicked_sub_thread // Access: Public -// Description: Called by the P3DSplashWindow code when the user -// clicks the button visible on the splash window. +// Description: Called by the P3DSplashWindow code (maybe in a +// sub-thread) when the user clicks the button visible +// on the splash window. This will forward the event to +// the main thread via the request callback mechanism. //////////////////////////////////////////////////////////////////// void P3DInstance:: -splash_button_clicked() { +splash_button_clicked_sub_thread() { + cerr << "splash sub\n"; + TiXmlDocument *doc = new TiXmlDocument; + TiXmlElement *xrequest = new TiXmlElement("request"); + xrequest->SetAttribute("rtype", "notify"); + xrequest->SetAttribute("message", "buttonclick"); + doc->LinkEndChild(xrequest); + + add_raw_request(doc); +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DInstance::splash_button_clicked_main_thread +// Access: Public +// Description: Called only in the main thread, indirectly from +// splash_button_clicked_sub_thread(), as the result of +// the user clicking on the button visible in the splash +// window. +//////////////////////////////////////////////////////////////////// +void P3DInstance:: +splash_button_clicked_main_thread() { + cerr << "splash main\n"; if (!_p3d_trusted) { auth_button_clicked(); } else if (_session == NULL) { @@ -954,6 +979,17 @@ check_p3d_signature() { return true; } + /* + if (_browser_script_object != NULL) { + P3D_object *result = P3D_OBJECT_EVAL(_browser_script_object, "if (confirm('test')) { window.open('', 'test', ''); }"); + cerr << "result = " << result << "\n"; + if (result != NULL) { + cerr << "formatted: " << *result << "\n"; + P3D_OBJECT_DECREF(result); + } + } + */ + // Temporary hack: disabling further security checks until this code // is complete. return true; @@ -1298,6 +1334,14 @@ handle_notify_request(const string &message) { CFRunLoopRef run_loop = CFRunLoopGetCurrent(); CFRunLoopAddTimer(run_loop, _frame_timer, kCFRunLoopCommonModes); #endif // __APPLE__ + + } else if (message == "buttonclick") { + // We just got a special "button click" message from the + // sub-thread. This case is a little unusual, as it came from the + // splash window and not from Python (we presumably haven't even + // started Python yet). We use this as a sneaky way to forward + // the event from the sub-thread to the main thread. + splash_button_clicked_main_thread(); } } diff --git a/direct/src/plugin/p3dInstance.h b/direct/src/plugin/p3dInstance.h index 3219c6aac5..f6ffc14650 100644 --- a/direct/src/plugin/p3dInstance.h +++ b/direct/src/plugin/p3dInstance.h @@ -101,7 +101,8 @@ public: void request_refresh(); TiXmlElement *make_xml(); - void splash_button_clicked(); + void splash_button_clicked_sub_thread(); + void splash_button_clicked_main_thread(); void auth_button_clicked(); void play_button_clicked(); diff --git a/direct/src/plugin/p3dSplashWindow.cxx b/direct/src/plugin/p3dSplashWindow.cxx index 6c670b0cc1..a8febdacc4 100755 --- a/direct/src/plugin/p3dSplashWindow.cxx +++ b/direct/src/plugin/p3dSplashWindow.cxx @@ -473,11 +473,13 @@ set_mouse_data(int mouse_x, int mouse_y, bool mouse_down) { // notifies the instance. It's a virtual method to give // subclasses a chance to redirect this message to the // main thread or process, as necessary. +// +// Note that this method might be called in a sub-thread. //////////////////////////////////////////////////////////////////// void P3DSplashWindow:: button_click_detected() { assert(_inst != NULL); - _inst->splash_button_clicked(); + _inst->splash_button_clicked_sub_thread(); } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/plugin/p3dWinSplashWindow.cxx b/direct/src/plugin/p3dWinSplashWindow.cxx index bd6f0e61b3..cbe4d9ee09 100755 --- a/direct/src/plugin/p3dWinSplashWindow.cxx +++ b/direct/src/plugin/p3dWinSplashWindow.cxx @@ -220,12 +220,7 @@ unregister_window_class() { //////////////////////////////////////////////////////////////////// void P3DWinSplashWindow:: button_click_detected() { - // Since this message is detected in the sub-thread in the Windows - // case, we have to protect ourselves from re-entry by grabbing the - // global _api_lock. - ACQUIRE_LOCK(_api_lock); P3DSplashWindow::button_click_detected(); - RELEASE_LOCK(_api_lock); } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/plugin/p3dX11SplashWindow.cxx b/direct/src/plugin/p3dX11SplashWindow.cxx index ec3428db46..bf5b77fe89 100755 --- a/direct/src/plugin/p3dX11SplashWindow.cxx +++ b/direct/src/plugin/p3dX11SplashWindow.cxx @@ -440,9 +440,7 @@ rt_handle_request(TiXmlDocument *doc) { // click notification. delete doc; - ACQUIRE_LOCK(_api_lock); P3DSplashWindow::button_click_detected(); - RELEASE_LOCK(_api_lock); } ////////////////////////////////////////////////////////////////////