-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
VariantParser: NaN, INF read/write bug fixed #47497
VariantParser: NaN, INF read/write bug fixed #47497
Conversation
Would you rebase (this and the 3.x PR) again? Github is reporting a conflict in the modified file. By the way, I ran into a related issue: Infinity gets stored as 1.#INF but parsed as 1.0. I had a look at the changes in this pull request, and I believe it fixes the problem. |
da23ead
to
2d4f30d
Compare
I tried the artifacts made by github for this (and also for the 3.x branch), and I can confirm it solves the both the original bug (Which was about RayCast2D), and the related issue I was having. However:
|
I went and tried both RayCast(3D) and RayCast2D with infinity on both the 3.x and this one, and they don't work. So, yeah, they can spam "The axis Vector3 must be normalized.", it is fine. If anything RayCast2D should complain too. |
@theraot I don't believe the serialization is related to how values show/input in the inspector (but I could be wrong). You may want to look for/submit bug reports for those issues. |
@briansemrau This PR does not change how I type infinity in the inspector (I type the constant INF, other constants work, e.g. PI). But it does change how it shows. In both Godot 3.3.3 and Godot 3.4 beta5 infinity shows as 1.#IO (and there were issues about that). But with this PR it shows as inf. Thus I believe it is your change, and I would prefer if it matched the constant INF. However, in other builds of the master branch it did show as inf even without this PR. Which I thought was a compiler issue, at least according to @bruvzg, see #40589 (comment). But perhaps it no longer uses the serialization in Godot 4.0. Anyway, I suppose this could be merged and then I could open an issue afterwards. |
core/variant/variant_parser.cpp
Outdated
@@ -90,6 +90,17 @@ const char *VariantParser::tk_name[TK_MAX] = { | |||
"ERROR" | |||
}; | |||
|
|||
static double sfixtor(const String &p_sfix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do sfixtor
and sfix
mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's a misunderstanding of what rtosfix
means, trying to reverse this around?
rtosfix
means "Real TO String FIX", i.e. it fixes the conversion of reals to strings.
So this should be storfix
with e.g. parameter p_str
.
Or both should be renamed to be more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is carryover from the abandoned PR. I think keeping naming inline with core/string/ustring.h
is a good idea, but perhaps a function renaming PR is in the future if it's not clear enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated so sfixtor
is renamed to stor_fix
and rtosfix
is renamed to rtos_fix
.
core/variant/variant_parser.cpp
Outdated
if (p_value > 0) { | ||
return "inf"; | ||
} else { | ||
return "inf_neg"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason why this is inf_neg
and not -inf
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's to avoid having this be parsed as a TK_NUMBER
token instead of TK_IDENTIFIER
.
Added some review comments, but overall this PR looks good to me. It's an important bugfix too.
|
4520611
to
4eae90a
Compare
4eae90a
to
3f3ed5d
Compare
I'll elaborate why I would prefer it to match: With PI, for example, I type PI and the inspector changes it to 3.142. The inspector changed it, that is fine. Now, if I type 3.142, I get 3.142. That is, I can type the same way it is represented. In general, if I see a number in the inspector panel, I can also type that number. And if I type a number, I get that number. Perhaps with some rounding. However, with infinity I need to type INF. Which the inspector shows as inf. However, if I type inf, it does not work (because inf is not a GDScript constant). It is instinct to try to write it the way I see it written. To be fair, this is not the issue being dealt with here (and there are other avenues to fix it, such as adding inf as a constant). I'm willing to open issues for that and for warning in RayCasts (my current thinking is that those could be proposals, and there could be discussion on how best to approach them). |
@theraot I understand, but in practice it's the same, you type the This seems to be the pre-existing behavior on platforms not affected by #40589, without this PR for me typing One could use I also don't think that inputting |
For the record, the same would be true in C++: #include <cmath>
#include <cstdio>
int main() {
printf("%f\n", INFINITY);
return 0;
} Prints |
Thanks! |
Fix: #40589, supersedes #40619.
This is a rebase of #40619 due to inactivity on that PR.
This was tested on Windows 10 with Visual Studio 2019.