-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Fix no cast in Ref<T>::ref() #469
Fix no cast in Ref<T>::ref() #469
Conversation
I'm not sure but maybe more leak tests are needed |
@@ -21,7 +21,7 @@ class Ref { | |||
|
|||
unref(); | |||
|
|||
reference = p_from.reference; | |||
reference = Object::cast_to<T>(p_from.reference); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast makes sense, but looks like the location is not right. ref
here expects a reference where T
is the same between the source and destination references. I'm not even sure why it gets called (or even compiling?) while InputEventScreenTouch
and InputEventMouseButton
are incompatible types? Or perhaps the syntax without T
means "any T"? I see it's used with the basic Reference
somewhere so it might be a problem.
I would have expected this cast to occur in a function that expects a different T
. If T
is the same, no cast should occur, otherwise it would slow down every place the wrapper is assigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok the real place to put the cast should actually be the places with // TODO We need a safe cast
.
The reason ref
ends up assigning the pointer is because of a cast that happened already, but it was done without any check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
Can I close this pull request and let you fix this issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm working on a fix, though having a bit of trouble enforcing T being a Reference at compile-time... might be able to fix the cast but to have the extra nicety it might need more work
New PR: #480 |
Godot versions:
Windows 3.2.4 godotengine/godot#43554
Linux 3.2.3.stable
GDNative: #451
On Windows with the current Ref implementation on master brach, this code will crash after the first get_position because the reference is actualy nullptr for InputEventScreenTouch type and it has same address as iemb reference.
On Linux no crash occurs but types not casted correctly too. Linux just use wrong memory segment and display zeroes or random values.
After this fix, the behavior of Windows and Linux is the same and correct as in normal modules
Also I tested this with my custom classes
Without a fix Windows and Linux builds crashed on call to invalid Dictionary
With fix:
Now the original Godot code and the code here are not the same, but now it works for me.