-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_DEBUG is not defined when compiling Godot in debug mode on Windows #31608
Labels
Milestone
Comments
Feel free to make a PR, including a patch for oidn if it's still needed. This should be dependent on the diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 705e83dace..c9030fc982 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -339,10 +339,11 @@ def configure_msvc(env, vcvars_msvc_config):
## Compile/link flags
+ runtime_suffix = "d" if env["optimize"] in ["debug", "none"] else ""
if env["use_static_cpp"]:
- env.AppendUnique(CCFLAGS=["/MT"])
+ env.AppendUnique(CCFLAGS=["/MT" + runtime_suffix])
else:
- env.AppendUnique(CCFLAGS=["/MD"])
+ env.AppendUnique(CCFLAGS=["/MD" + runtime_suffix])
if env["arch"] == "x86_32":
env["x86_libtheora_opt_vc"] = True Or another option which may work around the diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 705e83dace..2386ad159c 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -339,10 +339,14 @@ def configure_msvc(env, vcvars_msvc_config):
## Compile/link flags
- if env["use_static_cpp"]:
- env.AppendUnique(CCFLAGS=["/MT"])
+ if env["optimize"] in ["debug", "none"]:
+ # Always use dynamic runtime, debug static CRT is breaks thread_local.
+ env.AppendUnique(CCFLAGS=["/MDd"])
else:
- env.AppendUnique(CCFLAGS=["/MD"])
+ if env["use_static_cpp"]:
+ env.AppendUnique(CCFLAGS=["/MT"])
+ else:
+ env.AppendUnique(CCFLAGS=["/MD"])
if env["arch"] == "x86_32":
env["x86_libtheora_opt_vc"] = True I guess I'll PR that for testing. |
rohanrhu
pushed a commit
to rohanrhu/godot
that referenced
this issue
Dec 28, 2022
rohanrhu
pushed a commit
to rohanrhu/godot
that referenced
this issue
Dec 28, 2022
Streq
pushed a commit
to Streq/godot
that referenced
this issue
Feb 9, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Godot 3.2 master
I am writing a module making use of STL because Godot containers are not fit for some use cases, and I realized that even in debug mode, they don't do any boundary checks. It would have been useful to have when I ran into heap corruption...
Then I realized it's because
_DEBUG
, a macro usually active on Windows debug builds to enable standard lib checks, was not defined. Is there a reason for that?https://docs.microsoft.com/en-us/visualstudio/debugger/enabling-debug-features-in-visual-cpp-d-debug?view=vs-2019
I tried to enable it in my module, but then linking with the rest of Godot fails.
I verified with this
EDIT: this can be fixed by modifying
platform/windows/detect.py
:(of course we need to do this only in dev builds)
/MTd
both defines_DEBUG
and uses the debug runtime library, as_DEBUG
alone won't work. Unfortunately, due to a bug in the debug runtime, anythread_local
defined in global space holding a standard library container will cause an error when a debugger is attached.See:
baldurk/renderdoc#1743
https://developercommunity.visualstudio.com/t/race-condition-on-g-tss-mutex-with-static-crt/672664
An easy workaround is to wrap these
thread_local
in a function, which will make them created on-demand instead of application start.The only place I had to fix in Godot is the thirdparty
oidn
, which defines athread_local
inoidn/core/device.cpp
.The text was updated successfully, but these errors were encountered: