0031769: Application Framework - regression : can not initialize two kinds of applica...
authormpv <mpv@opencascade.com>
Tue, 15 Sep 2020 13:20:01 +0000 (16:20 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 18 Sep 2020 14:46:56 +0000 (17:46 +0300)
src/TObj/TObj_Application.cxx
tests/bugs/caf/bug31769 [new file with mode: 0644]

index 7e889a4..17bb84e 100644 (file)
@@ -42,7 +42,17 @@ Handle(TObj_Application) TObj_Application::GetInstance()
   Handle(CDF_Session) aSession = CDF_Session::Create();
   Handle(CDF_Application) anApp;
   if (aSession->FindApplication(OSD_Thread::Current(), anApp))
-    return Handle(TObj_Application)::DownCast(anApp);
+  {
+    Handle(TObj_Application) aTObjApp = Handle(TObj_Application)::DownCast(anApp);
+    if (!aTObjApp.IsNull())
+      return aTObjApp;
+    // If in session application of another type is already registered, use this global
+    // application, alone, outside of the session (as a workaround for DRAW scripting where
+    // many kinds of applications can be required).
+    static Handle(TObj_Application) THE_TOBJ_APP(new TObj_Application);
+    return THE_TOBJ_APP;
+  }
+  // It will register this application in the session.
   return new TObj_Application;
 }
 
diff --git a/tests/bugs/caf/bug31769 b/tests/bugs/caf/bug31769
new file mode 100644 (file)
index 0000000..852526a
--- /dev/null
@@ -0,0 +1,6 @@
+puts "==========="
+puts "0031769: Application Framework - regression : can not initialize two kinds of application in one thread"
+puts "==========="
+
+# loading of ALL initializes TDOCStd_Application, loading TOBJ initializes TObj_Application
+pload ALL TOBJ