[Bf-blender-cvs] [e673cfc2d70] master: Fix T95099: Have launcher wait for Blender exit

Jens Ehrhardt noreply at git.blender.org
Mon Jan 24 16:43:43 CET 2022


Commit: e673cfc2d703da93e6df72fc657660b8235494e8
Author: Jens Ehrhardt
Date:   Mon Jan 24 08:43:38 2022 -0700
Branches: master
https://developer.blender.org/rBe673cfc2d703da93e6df72fc657660b8235494e8

Fix T95099: Have launcher wait for Blender exit

unity launches blender in background mode to do some
file conversions, ever since the launcher got introduced
this process broke.

The root cause here is: Unity looks up the default program
to launch .blend files with, which is now the launcher, then
launches it in background mode with a script to export the data.

The launcher however was designed to exit as quickly as
possible so there would not be an extra background process
lingering. It does not wait for blender to exit and does not
pass back any error codes.

This broke unity's workflow since it assumed if the process
exits and succeeds the data *must* be ready for reading which
no longer holds true.

This change keeps the launcher design as was previously,
*except* when launching in background mode, then it
waits and passes back any error codes, thus restoring
unity's workflow.

Differential Revision: https://developer.blender.org/D13894
Reviewed by: LazyDodo, Brecht

===================================================================

M	source/creator/blender_launcher_win32.c

===================================================================

diff --git a/source/creator/blender_launcher_win32.c b/source/creator/blender_launcher_win32.c
index 86b0f4f3b97..f19438ad907 100644
--- a/source/creator/blender_launcher_win32.c
+++ b/source/creator/blender_launcher_win32.c
@@ -79,7 +79,26 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
   BOOL success = CreateProcess(
       path, buffer, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &siStartInfo, &procInfo);
 
+  DWORD returnValue = success ? 0 : -1;
+
   if (success) {
+    /* If blender-launcher is called with background command line flag,
+     * wait for the blender process to exit and return its return value. */
+    BOOL background = FALSE;
+    int argc = 0;
+    LPWSTR *argv = CommandLineToArgvW(pCmdLine, &argc);
+    for (int i = 0; i < argc; i++) {
+      if ((wcscmp(argv[i], L"-b") == 0) || (wcscmp(argv[i], L"--background") == 0)) {
+        background = TRUE;
+        break;
+      }
+    }
+
+    if (background) {
+      WaitForSingleObject(procInfo.hProcess, INFINITE);
+      GetExitCodeProcess(procInfo.hProcess, &returnValue);
+    }
+
     /* Handles in PROCESS_INFORMATION must be closed with CloseHandle when they are no longer
      * needed - MSDN. Closing the handles will NOT terminate the thread/process that we just
      * started. */
@@ -88,5 +107,5 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
   }
 
   free(buffer);
-  return success ? 0 : -1;
+  return returnValue;
 }



More information about the Bf-blender-cvs mailing list