Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Ehrhardt <Jens_Eopus>2022-01-24 18:43:38 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2022-01-25 11:44:31 +0300
commitddf92d719bd41fd824affd5fc98f9fd8249b4b15 (patch)
tree310b441565acf9d44d6c8ede94d12e92fc8422f3
parentadd07576a090186dde7858bcb6e68f9cf059f902 (diff)
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
-rw-r--r--source/creator/blender_launcher_win32.c21
1 files changed, 20 insertions, 1 deletions
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;
}