You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GDNative's api.json doesn't give any information if a method would return null or not, the binding at the moment assumes that null will never returned hence why we always return a non-nullable type. If Godot returns null, our binding will crash here.
Our current plan to avoid this is to maintain a list of methods that are known to return null, this data will supplement api.json when we are generating the engine types. However, due to the undocumented nature of Godot, it will be impossible for us to track all methods that can return null all at once. There will be cases were users would be stuck, because of the failure I mentioned above.
I propose that we should change our code generation to check if the return value is null and just return an empty instance of the expected return type.
val ptr =...
if (isNull(ptr) {
returnGodot.noInitZone { Node() }
}
returnTypeManager.wrap(ptr) asNode
This will ensure that Object::ptr is not initialized - which we can use to check if a given object is "null".
fun <T:Object> T.isNull() =!this::ptr.isInitialized
Note that this api should be used sparingly, only when the user has encountered the problem described above. Therefore we should mark this method as @Deprecated and set the deprecation message to say that the user should file a ticket in Github about which method needs to return a nullable type.
The text was updated successfully, but these errors were encountered:
GDNative's
api.json
doesn't give any information if a method would return null or not, the binding at the moment assumes that null will never returned hence why we always return a non-nullable type. If Godot returns null, our binding will crash here.Our current plan to avoid this is to maintain a list of methods that are known to return null, this data will supplement
api.json
when we are generating the engine types. However, due to the undocumented nature of Godot, it will be impossible for us to track all methods that can return null all at once. There will be cases were users would be stuck, because of the failure I mentioned above.I propose that we should change our code generation to check if the return value is
null
and just return an empty instance of the expected return type.This will ensure that
Object::ptr
is not initialized - which we can use to check if a given object is "null".Note that this api should be used sparingly, only when the user has encountered the problem described above. Therefore we should mark this method as
@Deprecated
and set the deprecation message to say that the user should file a ticket in Github about which method needs to return a nullable type.The text was updated successfully, but these errors were encountered: