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:
Diffstat (limited to 'source/creator/creator.c')
-rw-r--r--source/creator/creator.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c
index a3bce79b6e7..1596fe5359c 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -300,6 +300,7 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
#ifdef WITH_LIBMV
BLI_argsPrintArgDoc(ba, "--debug-libmv");
#endif
+ BLI_argsPrintArgDoc(ba, "--debug-memory");
BLI_argsPrintArgDoc(ba, "--debug-jobs");
BLI_argsPrintArgDoc(ba, "--debug-python");
@@ -439,6 +440,12 @@ static int debug_mode_libmv(int UNUSED(argc), const char **UNUSED(argv), void *U
}
#endif
+static int debug_mode_memory(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+{
+ MEM_set_memory_debug();
+ return 0;
+}
+
static int set_debug_value(int argc, const char **argv, void *UNUSED(data))
{
if (argc > 1) {
@@ -1384,6 +1391,7 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
#ifdef WITH_LIBMV
BLI_argsAdd(ba, 1, NULL, "--debug-libmv", "\n\tEnable debug messages from libmv library", debug_mode_libmv, NULL);
#endif
+ BLI_argsAdd(ba, 1, NULL, "--debug-memory", "\n\tEnable fully guarded memory allocation and debugging", debug_mode_memory, NULL);
BLI_argsAdd(ba, 1, NULL, "--debug-value", "<value>\n\tSet debug value of <value> on startup\n", set_debug_value, NULL);
BLI_argsAdd(ba, 1, NULL, "--debug-jobs", "\n\tEnable time profiling for background jobs.", debug_mode_generic, (void *)G_DEBUG_JOBS);
@@ -1454,23 +1462,50 @@ int main(int argc, const char **UNUSED(argv_c)) /* Do not mess with const */
int main(int argc, const char **argv)
#endif
{
- bContext *C = CTX_create();
+ bContext *C;
SYS_SystemHandle syshandle;
#ifndef WITH_PYTHON_MODULE
bArgs *ba;
#endif
-#ifdef WIN32
+#ifdef WIN32 /* Win32 Unicode Args */
+ /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialised
+ * (it depends on the args passed in, which is what we're getting here!)
+ */
wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
+ char **argv = malloc(argc * sizeof(char *));
int argci = 0;
- char **argv = MEM_mallocN(argc * sizeof(char *), "argv array");
+
for (argci = 0; argci < argc; argci++) {
argv[argci] = alloc_utf_8_from_16(argv_16[argci], 0);
}
+
LocalFree(argv_16);
#endif
+ /* NOTE: Special exception for guarded allocator type switch:
+ * we need to perform switch from lock-free to fully
+ * guarded allocator before any allocation happened.
+ */
+ {
+ int i;
+ for (i = 0; i < argc; i++) {
+ if (STREQ(argv[i], "--debug") || STREQ(argv[i], "-d") ||
+ STREQ(argv[i], "--debug-memory"))
+ {
+ printf("Switching to fully guarded memory allocator.\n");
+ MEM_use_guarded_allocator();
+ break;
+ }
+ else if (STREQ(argv[i], "--")) {
+ break;
+ }
+ }
+ }
+
+ C = CTX_create();
+
#ifdef WITH_PYTHON_MODULE
#ifdef __APPLE__
environ = *_NSGetEnviron();
@@ -1641,7 +1676,7 @@ int main(int argc, const char **argv)
while (argci) {
free(argv[--argci]);
}
- MEM_freeN(argv);
+ free(argv);
argv = NULL;
#endif