Skip to content
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

Use safer casts in Ref<T> #480

Merged
merged 1 commit into from
Jan 31, 2021
Merged

Conversation

Zylann
Copy link
Collaborator

@Zylann Zylann commented Dec 8, 2020

Ref<T> now uses Object::cast_to, which should be safer. The previous cast could cause undefined behavior if the types were incompatible, now it should return null, which can be checked with .is_valid() or is_null().

I also attempted to add a static_assert to enforce T to derive from Reference, however this would force any mention of Ref<T> to also #include the definition of T, which might not be desirable when forward-declarations are used to speed up compilation (as bindings are currently generated), so I haven't included it.

Should fix #76

@Calinou Calinou added the enhancement This is an enhancement on the current functionality label Dec 8, 2020
@Zylann Zylann merged commit 18e1b26 into godotengine:master Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an enhancement on the current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ref<T> pointer cast is unsafe
2 participants