Creator: move to C++ #110539
|
@ -81,6 +81,11 @@ if(WITH_TBB)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# Windows.h will define min/max macros that will collide with the stl versions.
|
||||
add_definitions(-DNOMINMAX)
|
||||
endif()
|
||||
|
||||
if(WITH_USD)
|
||||
# USD links libMaterialX, when using pre-compiled libraries
|
||||
# ensures `usd_ms` can find `MaterialXRender` and friends.
|
||||
|
@ -140,9 +145,9 @@ endif()
|
|||
|
||||
# Setup the EXE sources and `buildinfo`.
|
||||
set(SRC
|
||||
creator.c
|
||||
creator_args.c
|
||||
creator_signals.c
|
||||
creator.cc
|
||||
creator_args.cc
|
||||
creator_signals.cc
|
||||
|
||||
creator_intern.h
|
||||
)
|
||||
|
|
|
@ -120,17 +120,13 @@
|
|||
* \{ */
|
||||
|
||||
/* written to by 'creator_args.c' */
|
||||
struct ApplicationState app_state = {
|
||||
.signal =
|
||||
{
|
||||
.use_crash_handler = true,
|
||||
.use_abort_handler = true,
|
||||
},
|
||||
.exit_code_on_error =
|
||||
{
|
||||
.python = 0,
|
||||
},
|
||||
};
|
||||
ApplicationState app_state = []() {
|
||||
ApplicationState app_state{};
|
||||
app_state.signal.use_crash_handler = true;
|
||||
app_state.signal.use_abort_handler = true;
|
||||
app_state.exit_code_on_error.python = 0;
|
||||
return app_state;
|
||||
}();
|
||||
|
||||
/** \} */
|
||||
|
||||
|
@ -159,7 +155,7 @@ struct CreatorAtExitData {
|
|||
#endif
|
||||
|
||||
#ifdef USE_WIN32_UNICODE_ARGS
|
||||
const char **argv;
|
||||
char **argv;
|
||||
int argv_num;
|
||||
#endif
|
||||
|
||||
|
@ -170,12 +166,12 @@ struct CreatorAtExitData {
|
|||
|
||||
static void callback_main_atexit(void *user_data)
|
||||
{
|
||||
struct CreatorAtExitData *app_init_data = user_data;
|
||||
struct CreatorAtExitData *app_init_data = static_cast<CreatorAtExitData *>(user_data);
|
||||
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
if (app_init_data->ba) {
|
||||
BLI_args_destroy(app_init_data->ba);
|
||||
app_init_data->ba = NULL;
|
||||
app_init_data->ba = nullptr;
|
||||
}
|
||||
#else
|
||||
UNUSED_VARS(app_init_data); /* May be unused. */
|
||||
|
@ -187,7 +183,7 @@ static void callback_main_atexit(void *user_data)
|
|||
free((void *)app_init_data->argv[--app_init_data->argv_num]);
|
||||
}
|
||||
free((void *)app_init_data->argv);
|
||||
app_init_data->argv = NULL;
|
||||
app_init_data->argv = nullptr;
|
||||
}
|
||||
#else
|
||||
UNUSED_VARS(app_init_data); /* May be unused. */
|
||||
|
@ -196,7 +192,7 @@ static void callback_main_atexit(void *user_data)
|
|||
|
||||
static void callback_clg_fatal(void *fp)
|
||||
{
|
||||
BLI_system_backtrace(fp);
|
||||
BLI_system_backtrace(static_cast<FILE *>(fp));
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
@ -216,12 +212,12 @@ void main_python_exit(void);
|
|||
|
||||
/* Rename the 'main' function, allowing Python initialization to call it. */
|
||||
# define main main_python_enter
|
||||
static void *evil_C = NULL;
|
||||
static void *evil_C = nullptr;
|
||||
|
||||
# ifdef __APPLE__
|
||||
/* Environment is not available in macOS shared libraries. */
|
||||
# include <crt_externs.h>
|
||||
char **environ = NULL;
|
||||
char **environ = nullptr;
|
||||
# endif /* __APPLE__ */
|
||||
|
||||
#endif /* WITH_PYTHON_MODULE */
|
||||
|
@ -241,12 +237,12 @@ void *gmp_alloc(size_t size)
|
|||
{
|
||||
return scalable_malloc(size);
|
||||
}
|
||||
void *gmp_realloc(void *ptr, size_t UNUSED(old_size), size_t new_size)
|
||||
void *gmp_realloc(void *ptr, size_t /*old_size*/, size_t new_size)
|
||||
{
|
||||
return scalable_realloc(ptr, new_size);
|
||||
}
|
||||
|
||||
void gmp_free(void *ptr, size_t UNUSED(size))
|
||||
void gmp_free(void *ptr, size_t /*size*/)
|
||||
{
|
||||
scalable_free(ptr);
|
||||
}
|
||||
|
@ -268,6 +264,10 @@ void gmp_blender_init_allocator()
|
|||
/** \name Main Function
|
||||
* \{ */
|
||||
|
||||
#if defined(__APPLE__)
|
||||
extern "C" int GHOST_HACK_getFirstFile(char buf[]);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Blender's main function responsibilities are:
|
||||
* - setup subsystems.
|
||||
|
@ -277,7 +277,7 @@ void gmp_blender_init_allocator()
|
|||
*/
|
||||
int main(int argc,
|
||||
#ifdef USE_WIN32_UNICODE_ARGS
|
||||
const char **UNUSED(argv_c)
|
||||
const char ** /*argv_c*/
|
||||
#else
|
||||
const char **argv
|
||||
#endif
|
||||
|
@ -297,20 +297,20 @@ int main(int argc,
|
|||
/* --- end declarations --- */
|
||||
|
||||
/* Ensure we free data on early-exit. */
|
||||
struct CreatorAtExitData app_init_data = {NULL};
|
||||
struct CreatorAtExitData app_init_data = {nullptr};
|
||||
BKE_blender_atexit_register(callback_main_atexit, &app_init_data);
|
||||
|
||||
/* Un-buffered `stdout` makes `stdout` and `stderr` better synchronized, and helps
|
||||
* when stepping through code in a debugger (prints are immediately
|
||||
* visible). However disabling buffering causes lock contention on windows
|
||||
* see #76767 for details, since this is a debugging aid, we do not enable
|
||||
* the un-buffered behavior for release builds. */
|
||||
/* Un-buffered `stdout` makes `stdout` and `stderr` better synchronized, and helps
|
||||
* when stepping through code in a debugger (prints are immediately
|
||||
* visible). However disabling buffering causes lock contention on windows
|
||||
* see #76767 for details, since this is a debugging aid, we do not enable
|
||||
* the un-buffered behavior for release builds. */
|
||||
#ifndef NDEBUG
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
/* We delay loading of OPENMP so we can set the policy here. */
|
||||
/* We delay loading of OPENMP so we can set the policy here. */
|
||||
# if defined(_MSC_VER)
|
||||
_putenv_s("OMP_WAIT_POLICY", "PASSIVE");
|
||||
# endif
|
||||
|
@ -321,7 +321,7 @@ int main(int argc,
|
|||
/* NOTE: Can't use `guardedalloc` allocation here, as it's not yet initialized
|
||||
* (it depends on the arguments passed in, which is what we're getting here!) */
|
||||
wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
argv = malloc(argc * sizeof(char *));
|
||||
argv = static_cast<char **>(malloc(argc * sizeof(char *)));
|
||||
for (argv_num = 0; argv_num < argc; argv_num++) {
|
||||
argv[argv_num] = alloc_utf_8_from_16(argv_16[argv_num], 0);
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ int main(int argc,
|
|||
#endif
|
||||
|
||||
#ifdef WITH_BINRELOC
|
||||
br_init(NULL);
|
||||
br_init(nullptr);
|
||||
#endif
|
||||
|
||||
#ifdef WITH_LIBMV
|
||||
|
@ -420,7 +420,6 @@ int main(int argc,
|
|||
#if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE) && !defined(WITH_HEADLESS)
|
||||
/* Patch to ignore argument finder gives us (PID?) */
|
||||
if (argc == 2 && STRPREFIX(argv[1], "-psn_")) {
|
||||
extern int GHOST_HACK_getFirstFile(char buf[]);
|
||||
static char firstfilebuf[512];
|
||||
|
||||
argc = 1;
|
||||
|
@ -459,7 +458,7 @@ int main(int argc,
|
|||
|
||||
BKE_callback_global_init();
|
||||
|
||||
/* First test for background-mode (#Global.background) */
|
||||
/* First test for background-mode (#Global.background) */
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
ba = BLI_args_create(argc, (const char **)argv); /* skip binary path */
|
||||
|
||||
|
@ -473,7 +472,7 @@ int main(int argc,
|
|||
MEM_use_memleak_detection(false);
|
||||
|
||||
/* Parse environment handling arguments. */
|
||||
BLI_args_parse(ba, ARG_PASS_ENVIRONMENT, NULL, NULL);
|
||||
BLI_args_parse(ba, ARG_PASS_ENVIRONMENT, nullptr, nullptr);
|
||||
|
||||
#else
|
||||
/* Using preferences or user startup makes no sense for #WITH_PYTHON_MODULE. */
|
||||
|
@ -492,7 +491,7 @@ int main(int argc,
|
|||
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
/* First test for background-mode (#Global.background) */
|
||||
BLI_args_parse(ba, ARG_PASS_SETTINGS, NULL, NULL);
|
||||
BLI_args_parse(ba, ARG_PASS_SETTINGS, nullptr, nullptr);
|
||||
|
||||
main_signal_setup();
|
||||
#endif
|
||||
|
@ -530,9 +529,9 @@ int main(int argc,
|
|||
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
if (G.background == 0) {
|
||||
BLI_args_parse(ba, ARG_PASS_SETTINGS_GUI, NULL, NULL);
|
||||
BLI_args_parse(ba, ARG_PASS_SETTINGS_GUI, nullptr, nullptr);
|
||||
}
|
||||
BLI_args_parse(ba, ARG_PASS_SETTINGS_FORCE, NULL, NULL);
|
||||
BLI_args_parse(ba, ARG_PASS_SETTINGS_FORCE, nullptr, nullptr);
|
||||
#endif
|
||||
|
||||
WM_init(C, argc, (const char **)argv);
|
||||
|
@ -555,7 +554,7 @@ int main(int argc,
|
|||
FRS_set_context(C);
|
||||
#endif
|
||||
|
||||
/* OK we are ready for it */
|
||||
/* OK we are ready for it */
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
/* Handles #ARG_PASS_FINAL. */
|
||||
BLI_args_parse(ba, ARG_PASS_FINAL, main_args_handle_load_file, C);
|
||||
|
@ -571,14 +570,14 @@ int main(int argc,
|
|||
/* End argument parsing, allow memory leaks to be printed. */
|
||||
MEM_use_memleak_detection(true);
|
||||
|
||||
/* Paranoid, avoid accidental re-use. */
|
||||
/* Paranoid, avoid accidental re-use. */
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
ba = NULL;
|
||||
ba = nullptr;
|
||||
(void)ba;
|
||||
#endif
|
||||
|
||||
#ifdef USE_WIN32_UNICODE_ARGS
|
||||
argv = NULL;
|
||||
argv = nullptr;
|
||||
(void)argv;
|
||||
#endif
|
||||
|
||||
|
@ -606,7 +605,7 @@ int main(int argc,
|
|||
void main_python_exit(void)
|
||||
{
|
||||
WM_exit_ex((bContext *)evil_C, true, false);
|
||||
evil_C = NULL;
|
||||
evil_C = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,9 @@
|
|||
#ifndef WITH_PYTHON_MODULE
|
||||
|
||||
# if defined(__linux__) && defined(__GNUC__)
|
||||
# define _GNU_SOURCE
|
||||
# ifndef _GNU_SOURCE
|
||||
# define _GNU_SOURCE
|
||||
# endif
|
||||
# include <fenv.h>
|
||||
# endif
|
||||
|
||||
|
@ -61,7 +63,7 @@
|
|||
|
||||
/* set breakpoints here when running in debug mode, useful to catch floating point errors */
|
||||
# if defined(__linux__) || defined(_WIN32) || defined(OSX_SSE_FPE)
|
||||
static void sig_handle_fpe(int UNUSED(sig))
|
||||
static void sig_handle_fpe(int /*sig*/)
|
||||
{
|
||||
fprintf(stderr, "debug: SIGFPE trapped\n");
|
||||
}
|
||||
|
@ -91,10 +93,10 @@ static void sig_handle_crash_backtrace(FILE *fp)
|
|||
|
||||
static void sig_handle_crash(int signum)
|
||||
{
|
||||
/* Might be called after WM/Main exit, so needs to be careful about NULL-checking before
|
||||
/* Might be called after WM/Main exit, so needs to be careful about nullptr-checking before
|
||||
* de-referencing. */
|
||||
|
||||
wmWindowManager *wm = G_MAIN ? G_MAIN->wm.first : NULL;
|
||||
wmWindowManager *wm = G_MAIN ? static_cast<wmWindowManager *>(G_MAIN->wm.first) : nullptr;
|
||||
|
||||
# ifdef USE_WRITE_CRASH_BLEND
|
||||
if (wm && wm->undo_stack) {
|
||||
|
@ -149,7 +151,7 @@ static void sig_handle_crash(int signum)
|
|||
/* open the crash log */
|
||||
errno = 0;
|
||||
fp = BLI_fopen(filepath, "wb");
|
||||
if (fp == NULL) {
|
||||
if (fp == nullptr) {
|
||||
fprintf(stderr,
|
||||
"Unable to save '%s': %s\n",
|
||||
filepath,
|
||||
|
@ -193,7 +195,7 @@ extern LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS *ExceptionInfo)
|
|||
LPVOID address = ExceptionInfo->ExceptionRecord->ExceptionAddress;
|
||||
fprintf(stderr, "Error : EXCEPTION_STACK_OVERFLOW\n");
|
||||
fprintf(stderr, "Address : 0x%p\n", address);
|
||||
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, address, &mod)) {
|
||||
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, LPCSTR(address), &mod)) {
|
||||
if (GetModuleFileName(mod, modulename, MAX_PATH)) {
|
||||
fprintf(stderr, "Module : %s\n", modulename);
|
||||
}
|
||||
|
@ -208,7 +210,7 @@ extern LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS *ExceptionInfo)
|
|||
}
|
||||
# endif
|
||||
|
||||
static void sig_handle_abort(int UNUSED(signum))
|
||||
static void sig_handle_abort(int /*signum*/)
|
||||
{
|
||||
/* Delete content of temp dir! */
|
||||
BKE_tempdir_session_purge();
|
||||
|
@ -264,9 +266,9 @@ void main_signal_setup_fpe(void)
|
|||
# endif /* OSX_SSE_FPE */
|
||||
# if defined(_WIN32) && defined(_MSC_VER)
|
||||
/* enables all fp exceptions */
|
||||
_controlfp_s(NULL, 0, _MCW_EM);
|
||||
_controlfp_s(nullptr, 0, _MCW_EM);
|
||||
/* hide the ones we don't care about */
|
||||
_controlfp_s(NULL, _EM_DENORMAL | _EM_UNDERFLOW | _EM_INEXACT, _MCW_EM);
|
||||
_controlfp_s(nullptr, _EM_DENORMAL | _EM_UNDERFLOW | _EM_INEXACT, _MCW_EM);
|
||||
# endif /* _WIN32 && _MSC_VER */
|
||||
# endif
|
||||
}
|
Loading…
Reference in New Issue