Closed allenwp closed 1 day ago
Thanks!
I agree that it would make sense for there to be a warning or something when Godot protects against a crash in a debug build.
However, it looks like it's Godot (not godot-cpp) that's doing the protecting. In core/variant/variant_setget.cpp:
case ARRAY: {
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
int idx = r_iter;
#ifdef DEBUG_ENABLED
if (idx < 0 || idx >= arr->size()) {
r_valid = false;
return Variant();
}
#endif
return arr->get(idx);
} break;
So, perhaps the warning should be added to Godot, rather than godot-cpp as well?
We could certainly add something to godot-cpp (also within a DEBUG_ENABLED
), but Godot module code can make this same mistake too.
Oh, wow, from looking at that source file, there's a whole bunch of code in there that appears to behave differently in debug mode than release mode without any warnings or errors! 😬
But... this confuses me because when I tried copying this snippet of code into the editor source files and built the editor in release mode, I got the debug behaviour... Did I make a mistake when doing this test?
But... this confuses me because when I tried copying this snippet of code into the editor source files and built the editor in release mode, I got the debug behaviour... Did I make a mistake when doing this test?
The editor can't be built in release mode, it's always in debug mode.
The editor can't be built in release mode, it's always in debug mode.
🤯 I had no idea! There's clearly more for me to learn about this subject.
In this case, I'll open an issue in godotengine/godot instead.
Godot version
v4.3.stable.official [77dcf97d8]
godot-cpp version
4.3 56571dc584ee7d14919996c6d58fb5b35e64af63
System information
Godot v4.3.stable - Windows 10.0.22631 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 980 Ti (NVIDIA; 32.0.15.6603) - 13th Gen Intel(R) Core(TM) i7-13700K (24 Threads)
Issue description
Calling
Variant::iter_get
on an emptyArray
causes this crash, but only in release builds of the godot-cpp GDExtension:I cannot reproduce this release-only behaviour on builds of the Godot editor, so it appears to only behave this way on release builds of GDExtension.
This issue also happens with other types of
Array
, such asPackedVector4Array
. This makes me suspect that this sort of behaviour could exist elsewhere in GDExtension...Steps to reproduce
Write the following code:
Compile with
scons dev_build=yes
and note that there are no issues, warnings, or errors and value isnull
.Compile with
scons target=template_release
and note that the error and crash occur.Minimal reproduction project
Here is an example GDExtension: release-only-gdextension-crash.zip
scons dev_build=yes
andscons target=template_release
to generate GDExtension DLL filesdemo
folderHere is my compiler info:
Using SCons-detected MSVC version 14.3, arch x86_64