Add DISABLE_OBJECT_BINDING_GUARD compiler flag #1585
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The guard in
Wrapped::Wrapped(const StringName)
detects the partial initialization ofgodot::Object
subclasses. This is needed because usingnew
to allocate agodot::Object
subclass will result in unexpected crashes because the bindings for the instance have not been set.The side effect of this guard is that it also prevents any use of a
godot::Object
subclass on the stack.There are godot native types such as
godot::RegEx
that are safe to use on the stack, and are used that way throughout the godot source. Similarly, custom classes that subclassgodot::Object
may also be used safely on the stack1.In this commit, I add a compiler flag to disable this guard. This will allow godot-cpp users who understand the safety implications to use
godot::Object
subclasses on the stack.Footnotes
https://github.com/godotengine/godot-cpp/pull/1446#issuecomment-2351331480 ↩