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

Using INF as float breaks scene #40589

Closed
illogically opened this issue Jul 22, 2020 · 9 comments · Fixed by #47497
Closed

Using INF as float breaks scene #40589

illogically opened this issue Jul 22, 2020 · 9 comments · Fixed by #47497

Comments

@illogically
Copy link

Godot version:
v3.2.2.stable.mono.official

OS/device including version:

OS: Windows 10

Issue description:
After using a tool script to set a Raycast2D node's cast_to to positive y on infinity, I attempted to run the scene but the game simply crashes. After reopening the editor fails to parse the scene. Included in the log is the following:

 Invalid color code: #.
 scene/resources/resource_format_text.cpp:278 - res://Test.tscn:36 - Parse Error: Expected ',' or ')' in constructor
 Failed to load resource 'res://Test.tscn'.
 Failed loading resource: res://Test.tscn.
 editor/editor_data.cpp:567 - Index p_idx = 1 is out of bounds (edited_scene.size() = 1).

Steps to reproduce:

  1. Set RayCast2D "Cast To" to INF
  2. Run scene or close scene and reopen.

Minimal reproduction project:

INFbug.zip

@Calinou
Copy link
Member

Calinou commented Jul 22, 2020

See also previous occurrences of the same issue: #35388, #28883.

@pouleyKetchoupp
Copy link
Contributor

pouleyKetchoupp commented Jul 22, 2020

I've tested on Windows (latest 3.2 branch), and it looks like it's fixed for float variables but still occurs with Vector2.

Here's the script I'm using to set the values:

tool
extends Node

export(float) var test_float
export(Vector2) var test_vec2

func _ready():
	test_float = INF
	test_vec2 = Vector2(INF, INF)

Saved scene:

[gd_scene load_steps=2 format=2]

[ext_resource path="res://Node.gd" type="Script" id=1]

[node name="Node" type="Node"]
script = ExtResource( 1 )
test_float = inf
test_vec2 = Vector2( inf, inf )

Errors when loading the scene in the editor:

ERROR: ResourceInteractiveLoaderText::_parse_node_tag: res://Node.tscn:8 - Parse Error: Expected float in constructor
   At: scene\resources\resource_format_text.cpp:278
ERROR: Failed to load resource 'res://Node.tscn'.
   At: core\io\resource_loader.cpp:208
ERROR: Failed loading resource: res://Node.tscn.
   At: core\io\resource_loader.cpp:278
ERROR: EditorData::remove_scene: Index p_idx = 1 is out of bounds (edited_scene.size() = 1).
   At: editor\editor_data.cpp:567

@illogically
Copy link
Author

As a note, entering INF in the editor itself will set it to 1.#INF and displayed as 1.#IO

@bruvzg
Copy link
Member

bruvzg commented Jul 22, 2020

1.#INF and displayed as 1.#IO

This is non-standard format specific to pre-Visual Studio 2015 C runtime, all other CRTs should print it as inf.

@Calinou
Copy link
Member

Calinou commented Jul 22, 2020

Should the editor even allow entering values like INF in the inspector?

@ghost
Copy link

ghost commented Jul 22, 2020

This is a quite consistent 'problem'.
For example setting the far property of a camera to inf (by script or in editor) causes the camera to stop working.
I guess it is quite a task to make everything 'inf proof'. However godot is not the only software that doesn't like inf. So I always avoid it and just use very large numbers instead. I guess the point of inf is more to have it as output when something overflows, just like NaN. Maybe inf can be removed from gd script? (what is the use case that can't be solved by replacing it with a large value?)

@Calinou
Copy link
Member

Calinou commented Jul 22, 2020

@redoxcode We can prevent using INF in the inspector without removing the constant from GDScript. The inspector accepts expressions written in a ad-hoc language (see the Expression class), not GDScript.

See also #24531, which is tangentially related to this issue.

@ghost
Copy link

ghost commented Jul 22, 2020

I know. Still you would have a ton of code to make inf prove (since it can still be set to inf from script). On a second thought removing inf from gs script is really overkill. Maybe we just have to accept that some stuff breaks when set to inf (for now). Making everything inf prove is quite a task and maybe not worth it in some cases if the checks required decrease performance or bloat the code.
So maybe just removing inf from the inspector is a good solution.

ThakeeNathees added a commit to ThakeeNathees/godot that referenced this issue Jul 23, 2020
@Zylann
Copy link
Contributor

Zylann commented Oct 25, 2020

I had the same problem in 3.2.3. I did not input INF anywhere but as a result of setting some properties to particular values I ended up with an INF in the scene file and it made the scene impossible to load, due to an obscure parsing error, not because of the value itself. While the appearance of INF should be prevented as much as possible if it's not an expected value, I think it should not break scenes like that, it's not friendly at all. INF is a value floats can take so it should be supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants