Merge pull request #78517 from AThousandShips/callable_serialize

Ensure `RID`, `Callable`, and `Signal` are stored as strings
This commit is contained in:
Rémi Verschelde 2023-06-22 18:30:51 +02:00
commit de3d4e3cec
No known key found for this signature in database
GPG Key ID: C3336907360768E1
14 changed files with 122 additions and 37 deletions

View File

@ -865,12 +865,46 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_NUMBER) {
r_err_str = "Expected number as argument";
// Permit empty RID.
if (token.type == TK_PARENTHESIS_CLOSE) {
value = RID();
return OK;
} else if (token.type != TK_NUMBER) {
r_err_str = "Expected number as argument or ')'";
return ERR_PARSE_ERROR;
}
value = token.value;
value = RID::from_uint64(token.value);
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
r_err_str = "Expected ')'";
return ERR_PARSE_ERROR;
}
} else if (id == "Signal") {
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
r_err_str = "Expected '('";
return ERR_PARSE_ERROR;
}
// Load as empty.
value = Signal();
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
r_err_str = "Expected ')'";
return ERR_PARSE_ERROR;
}
} else if (id == "Callable") {
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_OPEN) {
r_err_str = "Expected '('";
return ERR_PARSE_ERROR;
}
// Load as empty.
value = Callable();
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@ -1832,6 +1866,24 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
case Variant::RID: {
RID rid = p_variant;
if (rid == RID()) {
p_store_string_func(p_store_string_ud, "RID()");
} else {
p_store_string_func(p_store_string_ud, "RID(" + itos(rid.get_id()) + ")");
}
} break;
// Do not really store these, but ensure that assignments are not empty.
case Variant::SIGNAL: {
p_store_string_func(p_store_string_ud, "Signal()");
} break;
case Variant::CALLABLE: {
p_store_string_func(p_store_string_ud, "Callable()");
} break;
case Variant::OBJECT: {
Object *obj = p_variant.get_validated_object();
@ -2129,6 +2181,8 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
} break;
default: {
ERR_PRINT("Unknown variant type");
return ERR_BUG;
}
}

View File

@ -1379,6 +1379,7 @@
"b": 2
}
[/codeblock]
[b]Note:[/b] Converting [Signal] or [Callable] is not supported and will result in an empty value for these types, regardless of their data.
</description>
</method>
<method name="weakref">

View File

@ -25,7 +25,7 @@
{"foo": "hello", "bar": true, "baz": 42, "color": Color(1, 1, 1, 1)}
[/codeblock]
</member>
<member name="font" type="RID" setter="set_font" getter="get_font">
<member name="font" type="RID" setter="set_font" getter="get_font" default="RID()">
Font resource used to render glyph.
</member>
<member name="glyph_count" type="int" setter="set_glyph_count" getter="get_glyph_count" default="0">

View File

@ -188,8 +188,8 @@
<return type="int" />
<param index="0" name="menu_root" type="String" />
<param index="1" name="label" type="String" />
<param index="2" name="callback" type="Callable" />
<param index="3" name="key_callback" type="Callable" />
<param index="2" name="callback" type="Callable" default="Callable()" />
<param index="3" name="key_callback" type="Callable" default="Callable()" />
<param index="4" name="tag" type="Variant" default="null" />
<param index="5" name="accelerator" type="int" enum="Key" default="0" />
<param index="6" name="index" type="int" default="-1" />
@ -211,8 +211,8 @@
<param index="0" name="menu_root" type="String" />
<param index="1" name="icon" type="Texture2D" />
<param index="2" name="label" type="String" />
<param index="3" name="callback" type="Callable" />
<param index="4" name="key_callback" type="Callable" />
<param index="3" name="callback" type="Callable" default="Callable()" />
<param index="4" name="key_callback" type="Callable" default="Callable()" />
<param index="5" name="tag" type="Variant" default="null" />
<param index="6" name="accelerator" type="int" enum="Key" default="0" />
<param index="7" name="index" type="int" default="-1" />
@ -234,8 +234,8 @@
<param index="0" name="menu_root" type="String" />
<param index="1" name="icon" type="Texture2D" />
<param index="2" name="label" type="String" />
<param index="3" name="callback" type="Callable" />
<param index="4" name="key_callback" type="Callable" />
<param index="3" name="callback" type="Callable" default="Callable()" />
<param index="4" name="key_callback" type="Callable" default="Callable()" />
<param index="5" name="tag" type="Variant" default="null" />
<param index="6" name="accelerator" type="int" enum="Key" default="0" />
<param index="7" name="index" type="int" default="-1" />
@ -257,8 +257,8 @@
<param index="0" name="menu_root" type="String" />
<param index="1" name="icon" type="Texture2D" />
<param index="2" name="label" type="String" />
<param index="3" name="callback" type="Callable" />
<param index="4" name="key_callback" type="Callable" />
<param index="3" name="callback" type="Callable" default="Callable()" />
<param index="4" name="key_callback" type="Callable" default="Callable()" />
<param index="5" name="tag" type="Variant" default="null" />
<param index="6" name="accelerator" type="int" enum="Key" default="0" />
<param index="7" name="index" type="int" default="-1" />
@ -280,8 +280,8 @@
<return type="int" />
<param index="0" name="menu_root" type="String" />
<param index="1" name="label" type="String" />
<param index="2" name="callback" type="Callable" />
<param index="3" name="key_callback" type="Callable" />
<param index="2" name="callback" type="Callable" default="Callable()" />
<param index="3" name="key_callback" type="Callable" default="Callable()" />
<param index="4" name="tag" type="Variant" default="null" />
<param index="5" name="accelerator" type="int" enum="Key" default="0" />
<param index="6" name="index" type="int" default="-1" />
@ -304,8 +304,8 @@
<param index="1" name="label" type="String" />
<param index="2" name="max_states" type="int" />
<param index="3" name="default_state" type="int" />
<param index="4" name="callback" type="Callable" />
<param index="5" name="key_callback" type="Callable" />
<param index="4" name="callback" type="Callable" default="Callable()" />
<param index="5" name="key_callback" type="Callable" default="Callable()" />
<param index="6" name="tag" type="Variant" default="null" />
<param index="7" name="accelerator" type="int" enum="Key" default="0" />
<param index="8" name="index" type="int" default="-1" />
@ -328,8 +328,8 @@
<return type="int" />
<param index="0" name="menu_root" type="String" />
<param index="1" name="label" type="String" />
<param index="2" name="callback" type="Callable" />
<param index="3" name="key_callback" type="Callable" />
<param index="2" name="callback" type="Callable" default="Callable()" />
<param index="3" name="key_callback" type="Callable" default="Callable()" />
<param index="4" name="tag" type="Variant" default="null" />
<param index="5" name="accelerator" type="int" enum="Key" default="0" />
<param index="6" name="index" type="int" default="-1" />

View File

@ -26,7 +26,7 @@
<return type="void" />
<param index="0" name="navigation_mesh" type="NavigationMesh" />
<param index="1" name="source_geometry_data" type="NavigationMeshSourceGeometryData3D" />
<param index="2" name="callback" type="Callable" />
<param index="2" name="callback" type="Callable" default="Callable()" />
<description>
Bakes the provided [param navigation_mesh] with the data from the provided [param source_geometry_data]. After the process is finished the optional [param callback] will be called.
</description>
@ -43,7 +43,7 @@
<param index="0" name="navigation_mesh" type="NavigationMesh" />
<param index="1" name="source_geometry_data" type="NavigationMeshSourceGeometryData3D" />
<param index="2" name="root_node" type="Node" />
<param index="3" name="callback" type="Callable" />
<param index="3" name="callback" type="Callable" default="Callable()" />
<description>
Parses the [SceneTree] for source geometry according to the properties of [param navigation_mesh]. Updates the provided [param source_geometry_data] resource with the resulting data. The resource can then be used to bake a navigation mesh with [method bake_from_source_geometry_data]. After the process is finished the optional [param callback] will be called.
[b]Note:[/b] This function needs to run on the main thread or with a deferred call as the SceneTree is not thread-safe.

View File

@ -10,7 +10,7 @@
<link title="Using NavigationPathQueryObjects">$DOCS_URL/tutorials/navigation/navigation_using_navigationpathqueryobjects.html</link>
</tutorials>
<members>
<member name="map" type="RID" setter="set_map" getter="get_map">
<member name="map" type="RID" setter="set_map" getter="get_map" default="RID()">
The navigation [code]map[/code] [RID] used in the path query.
</member>
<member name="metadata_flags" type="int" setter="set_metadata_flags" getter="get_metadata_flags" enum="NavigationPathQueryParameters2D.PathMetadataFlags" is_bitfield="true" default="7">

View File

@ -10,7 +10,7 @@
<link title="Using NavigationPathQueryObjects">$DOCS_URL/tutorials/navigation/navigation_using_navigationpathqueryobjects.html</link>
</tutorials>
<members>
<member name="map" type="RID" setter="set_map" getter="get_map">
<member name="map" type="RID" setter="set_map" getter="get_map" default="RID()">
The navigation [code]map[/code] [RID] used in the path query.
</member>
<member name="metadata_flags" type="int" setter="set_metadata_flags" getter="get_metadata_flags" enum="NavigationPathQueryParameters3D.PathMetadataFlags" is_bitfield="true" default="7">

View File

@ -803,7 +803,7 @@
<param index="1" name="anchor_a" type="Vector2" />
<param index="2" name="anchor_b" type="Vector2" />
<param index="3" name="body_a" type="RID" />
<param index="4" name="body_b" type="RID" />
<param index="4" name="body_b" type="RID" default="RID()" />
<description>
Makes the joint a damped spring joint, attached at the point [param anchor_a] (given in global coordinates) on the body [param body_a] and at the point [param anchor_b] (given in global coordinates) on the body [param body_b]. To set the parameters which are specific to the damped spring, see [method damped_spring_joint_set_param].
</description>
@ -814,8 +814,8 @@
<param index="1" name="groove1_a" type="Vector2" />
<param index="2" name="groove2_a" type="Vector2" />
<param index="3" name="anchor_b" type="Vector2" />
<param index="4" name="body_a" type="RID" />
<param index="5" name="body_b" type="RID" />
<param index="4" name="body_a" type="RID" default="RID()" />
<param index="5" name="body_b" type="RID" default="RID()" />
<description>
Makes the joint a groove joint.
</description>
@ -825,7 +825,7 @@
<param index="0" name="joint" type="RID" />
<param index="1" name="anchor" type="Vector2" />
<param index="2" name="body_a" type="RID" />
<param index="3" name="body_b" type="RID" />
<param index="3" name="body_b" type="RID" default="RID()" />
<description>
Makes the joint a pin joint. If [param body_b] is [code]RID()[/code], then [param body_a] is pinned to the point [param anchor] (given in global coordinates); otherwise, [param body_a] is pinned to [param body_b] at the point [param anchor] (given in global coordinates). To set the parameters which are specific to the pin joint, see [method pin_joint_set_param].
</description>

View File

@ -30,7 +30,7 @@
<member name="shape" type="Resource" setter="set_shape" getter="get_shape">
The [Shape2D] that will be used for collision/intersection queries. This stores the actual reference which avoids the shape to be released while being used for queries, so always prefer using this over [member shape_rid].
</member>
<member name="shape_rid" type="RID" setter="set_shape_rid" getter="get_shape_rid">
<member name="shape_rid" type="RID" setter="set_shape_rid" getter="get_shape_rid" default="RID()">
The queried shape's [RID] that will be used for collision/intersection queries. Use this over [member shape] if you want to optimize for performance using the Servers API:
[codeblocks]
[gdscript]

View File

@ -30,7 +30,7 @@
<member name="shape" type="Resource" setter="set_shape" getter="get_shape">
The [Shape3D] that will be used for collision/intersection queries. This stores the actual reference which avoids the shape to be released while being used for queries, so always prefer using this over [member shape_rid].
</member>
<member name="shape_rid" type="RID" setter="set_shape_rid" getter="get_shape_rid">
<member name="shape_rid" type="RID" setter="set_shape_rid" getter="get_shape_rid" default="RID()">
The queried shape's [RID] that will be used for collision/intersection queries. Use this over [member shape] if you want to optimize for performance using the Servers API:
[codeblocks]
[gdscript]

View File

@ -240,7 +240,7 @@
<param index="1" name="mesh" type="RID" />
<param index="2" name="transform" type="Transform2D" default="Transform2D(1, 0, 0, 1, 0, 0)" />
<param index="3" name="modulate" type="Color" default="Color(1, 1, 1, 1)" />
<param index="4" name="texture" type="RID" />
<param index="4" name="texture" type="RID" default="RID()" />
<description>
Draws a mesh created with [method mesh_create] with given [param transform], [param modulate] color, and [param texture]. This is used internally by [MeshInstance2D].
</description>
@ -273,7 +273,7 @@
<return type="void" />
<param index="0" name="item" type="RID" />
<param index="1" name="mesh" type="RID" />
<param index="2" name="texture" type="RID" />
<param index="2" name="texture" type="RID" default="RID()" />
<description>
Draws a 2D [MultiMesh] on the [CanvasItem] pointed to by the [param item] [RID]. See also [method CanvasItem.draw_multimesh].
</description>
@ -309,7 +309,7 @@
<param index="1" name="points" type="PackedVector2Array" />
<param index="2" name="colors" type="PackedColorArray" />
<param index="3" name="uvs" type="PackedVector2Array" default="PackedVector2Array()" />
<param index="4" name="texture" type="RID" />
<param index="4" name="texture" type="RID" default="RID()" />
<description>
Draws a 2D polygon on the [CanvasItem] pointed to by the [param item] [RID]. If you need more flexibility (such as being able to use bones), use [method canvas_item_add_triangle_array] instead. See also [method CanvasItem.draw_polygon].
</description>
@ -387,7 +387,7 @@
<param index="4" name="uvs" type="PackedVector2Array" default="PackedVector2Array()" />
<param index="5" name="bones" type="PackedInt32Array" default="PackedInt32Array()" />
<param index="6" name="weights" type="PackedFloat32Array" default="PackedFloat32Array()" />
<param index="7" name="texture" type="RID" />
<param index="7" name="texture" type="RID" default="RID()" />
<param index="8" name="count" type="int" default="-1" />
<description>
Draws a triangle array on the [CanvasItem] pointed to by the [param item] [RID]. This is internally used by [Line2D] and [StyleBoxFlat] for rendering. [method canvas_item_add_triangle_array] is highly flexible, but more complex to use than [method canvas_item_add_polygon].
@ -1797,7 +1797,7 @@
<method name="instances_cull_aabb" qualifiers="const">
<return type="PackedInt64Array" />
<param index="0" name="aabb" type="AABB" />
<param index="1" name="scenario" type="RID" />
<param index="1" name="scenario" type="RID" default="RID()" />
<description>
Returns an array of object IDs intersecting with the provided AABB. Only 3D nodes that inherit from [VisualInstance3D] are considered, such as [MeshInstance3D] or [DirectionalLight3D]. Use [method @GlobalScope.instance_from_id] to obtain the actual nodes. A scenario RID must be provided, which is available in the [World3D] you want to query. This forces an update for all resources queued to update.
[b]Warning:[/b] This function is primarily intended for editor usage. For in-game use cases, prefer physics collision.
@ -1806,7 +1806,7 @@
<method name="instances_cull_convex" qualifiers="const">
<return type="PackedInt64Array" />
<param index="0" name="convex" type="Plane[]" />
<param index="1" name="scenario" type="RID" />
<param index="1" name="scenario" type="RID" default="RID()" />
<description>
Returns an array of object IDs intersecting with the provided convex shape. Only 3D nodes that inherit from [VisualInstance3D] are considered, such as [MeshInstance3D] or [DirectionalLight3D]. Use [method @GlobalScope.instance_from_id] to obtain the actual nodes. A scenario RID must be provided, which is available in the [World3D] you want to query. This forces an update for all resources queued to update.
[b]Warning:[/b] This function is primarily intended for editor usage. For in-game use cases, prefer physics collision.
@ -1816,7 +1816,7 @@
<return type="PackedInt64Array" />
<param index="0" name="from" type="Vector3" />
<param index="1" name="to" type="Vector3" />
<param index="2" name="scenario" type="RID" />
<param index="2" name="scenario" type="RID" default="RID()" />
<description>
Returns an array of object IDs intersecting with the provided 3D ray. Only 3D nodes that inherit from [VisualInstance3D] are considered, such as [MeshInstance3D] or [DirectionalLight3D]. Use [method @GlobalScope.instance_from_id] to obtain the actual nodes. A scenario RID must be provided, which is available in the [World3D] you want to query. This forces an update for all resources queued to update.
[b]Warning:[/b] This function is primarily intended for editor usage. For in-game use cases, prefer physics collision.

View File

@ -6,6 +6,36 @@ should instead be used to justify these changes and describe how users should wo
========================================================================================================================
GH-78517
--------
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_check_item/arguments/2': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_check_item/arguments/3': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_icon_check_item/arguments/3': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_icon_check_item/arguments/4': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_icon_item/arguments/3': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_icon_item/arguments/4': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_icon_radio_check_item/arguments/3': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_icon_radio_check_item/arguments/4': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_item/arguments/2': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_item/arguments/3': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_multistate_item/arguments/4': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_multistate_item/arguments/5': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_radio_check_item/arguments/2': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/DisplayServer/methods/global_menu_add_radio_check_item/arguments/3': default_value changed value in new API, from "" to "Callable()".
Validate extension JSON: Error: Field 'classes/PhysicsServer2D/methods/joint_make_damped_spring/arguments/4': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/PhysicsServer2D/methods/joint_make_groove/arguments/4': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/PhysicsServer2D/methods/joint_make_groove/arguments/5': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/PhysicsServer2D/methods/joint_make_pin/arguments/3': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/RenderingServer/methods/canvas_item_add_mesh/arguments/4': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/RenderingServer/methods/canvas_item_add_multimesh/arguments/2': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/RenderingServer/methods/canvas_item_add_polygon/arguments/4': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/RenderingServer/methods/canvas_item_add_triangle_array/arguments/7': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/RenderingServer/methods/instances_cull_aabb/arguments/1': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/RenderingServer/methods/instances_cull_convex/arguments/1': default_value changed value in new API, from "" to "RID()".
Validate extension JSON: Error: Field 'classes/RenderingServer/methods/instances_cull_ray/arguments/2': default_value changed value in new API, from "" to "RID()".
The previous argument was a serialization bug, there's no actual API change.
GH-78237
--------
Validate extension JSON: Error: Field 'classes/WebRTCPeerConnectionExtension/methods/_create_data_channel/return_value': type changed value in new API, from "Object" to "WebRTCDataChannel".

View File

@ -47,7 +47,7 @@
</method>
</methods>
<members>
<member name="spawn_function" type="Callable" setter="set_spawn_function" getter="get_spawn_function">
<member name="spawn_function" type="Callable" setter="set_spawn_function" getter="get_spawn_function" default="Callable()">
Method called on all peers when for every custom [method spawn] requested by the authority. Will receive the [code]data[/code] parameter, and should return a [Node] that is not in the scene tree.
[b]Note:[/b] The returned node should [b]not[/b] be added to the scene with [method Node.add_child]. This is done automatically.
</member>

View File

@ -64,7 +64,7 @@
If [code]true[/code], the MultiplayerAPI will allow encoding and decoding of object during RPCs.
[b]Warning:[/b] Deserialized objects can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threat such as remote code execution.
</member>
<member name="auth_callback" type="Callable" setter="set_auth_callback" getter="get_auth_callback">
<member name="auth_callback" type="Callable" setter="set_auth_callback" getter="get_auth_callback" default="Callable()">
The callback to execute when when receiving authentication data sent via [method send_auth]. If the [Callable] is empty (default), peers will be automatically accepted as soon as they connect.
</member>
<member name="auth_timeout" type="float" setter="set_auth_timeout" getter="get_auth_timeout" default="3.0">