Skip to content

Commit

Permalink
Ensure RID, Callable, and Signal are stored as strings
Browse files Browse the repository at this point in the history
Prevents parser errors in `.tscn` and `.tres` files where the assignment
would otherwise be empty.
  • Loading branch information
AThousandShips committed Jun 22, 2023
1 parent e74bf83 commit 9159208
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 37 deletions.
60 changes: 57 additions & 3 deletions core/variant/variant_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
}

Expand Down
1 change: 1 addition & 0 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/CharFXTransform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
28 changes: 14 additions & 14 deletions doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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" />
Expand All @@ -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" />
Expand All @@ -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" />
Expand All @@ -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" />
Expand All @@ -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" />
Expand All @@ -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" />
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/NavigationMeshGenerator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/NavigationPathQueryParameters2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/NavigationPathQueryParameters3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
8 changes: 4 additions & 4 deletions doc/classes/PhysicsServer2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/PhysicsShapeQueryParameters2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/PhysicsShapeQueryParameters3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions doc/classes/RenderingServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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].
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
Loading

0 comments on commit 9159208

Please sign in to comment.