Fix null-check against uninitialized pointer in Gd::from_sys_init_opt()
#20
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.
Background: type-ptr is passed to a Godot FFI function, representing the return type as an output parameter. This type-ptr contains the address of an object-ptr.
Problem: the object-ptr was not initialized to null before passing it to the FFI function. Since these functions' return value is optional, they may not write to the return pointer (output parameter). However, code was still checking the object-ptr for being null after the FFI, when it could be uninitialized.
An additional point addressed by this PR is the relatively complex implementation around reusing
Gd::from_sys_init()
. Now,Gd::from_sys_init_opt()
directly usesGd::from_obj_sys()
, significantly simplifying the logic.This may fix the crash when starting Dodge-the-Creeps that some users on Linux reported.