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:
authorCampbell Barton <campbell@blender.org>2022-09-08 13:27:03 +0300
committerCampbell Barton <campbell@blender.org>2022-09-08 13:32:57 +0300
commit5e2d139ee30d88b474d3e7d65d5ff37d0be086b6 (patch)
tree160ffc1f82463a185d8011d35feb517bc170873b /source/creator
parent82fc52ffc88142e0fa29335e07595c87c173a3a6 (diff)
Fix Blender as a Python module for WIN32
BKE_appdir_program_path_init would override the module path extracted from the Python module, replacing it with the Python executable. This caused the data files not to be found and the module not to load.
Diffstat (limited to 'source/creator')
-rw-r--r--source/creator/creator.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c
index e7a803d383f..e7e9eeed79a 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -233,6 +233,12 @@ void gmp_blender_init_allocator()
/** \name Main Function
* \{ */
+/* When building as a Python module, don't use special argument handling
+ * so the module loading logic can control the `argv` & `argc`. */
+#if defined(WIN32) && !defined(WITH_PYTHON_MODULE)
+# define USE_WIN32_UNICODE_ARGS
+#endif
+
/**
* Blender's main function responsibilities are:
* - setup subsystems.
@@ -241,7 +247,7 @@ void gmp_blender_init_allocator()
* or exit immediately when running in background-mode.
*/
int main(int argc,
-#ifdef WIN32
+#ifdef USE_WIN32_UNICODE_ARGS
const char **UNUSED(argv_c)
#else
const char **argv
@@ -254,7 +260,7 @@ int main(int argc,
bArgs *ba;
#endif
-#ifdef WIN32
+#ifdef USE_WIN32_UNICODE_ARGS
char **argv;
int argv_num;
#endif
@@ -284,6 +290,7 @@ int main(int argc,
/* NOTE: cannot use `guardedalloc` allocation here, as it's not yet initialized
* (it depends on the arguments passed in, which is what we're getting here!)
*/
+# ifdef USE_WIN32_UNICODE_ARGS
{
wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
argv = malloc(argc * sizeof(char *));
@@ -296,7 +303,8 @@ int main(int argc,
app_init_data.argv = argv;
app_init_data.argv_num = argv_num;
}
-#endif /* WIN32 */
+# endif /* USE_WIN32_UNICODE_ARGS */
+#endif /* WIN32 */
/* NOTE: Special exception for guarded allocator type switch:
* we need to perform switch from lock-free to fully
@@ -388,7 +396,17 @@ int main(int argc,
#endif
/* Initialize path to executable. */
- BKE_appdir_program_path_init(argv[0]);
+ {
+#ifdef WITH_PYTHON_MODULE
+ /* NOTE(@campbellbarton): Always use `argv[0]` as is, when building as a Python module.
+ * Otherwise other methods of detecting the binary that override this argument
+ * which must point to the Python module for data-files to be detected. */
+ const bool strict = true;
+#else
+ const bool strict = false;
+#endif
+ BKE_appdir_program_path_init(argv[0], strict);
+ }
BLI_threadapi_init();