-
Notifications
You must be signed in to change notification settings - Fork 18
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
Replace huge advance value by a safer one with the same behavior #11
base: master
Are you sure you want to change the base?
Conversation
The `default.json` font file contains a font advance value of `1e400`. This value is too big to be represented as-is even by IEEE 754 64-bit floating point numbers as used by Java and, by extension, Minecraft. Gson, the JSON deserialization library used by Minecraft, cannot properly represent such a number either, but the deserialization process is lenient and chugs along with a practically close enough value. According to the ECMA JSON standard, numbers in JSON may be arbitrarily big, so such a number is technically within specification. However, the standard highlights the possibility that different programs disagree on the way they represent numbers, which in practice can cause interoperability issues. One such interoperability issue happens with PackSquash, which relies on `serde_json` for JSON parsing, and that parser (reasonbly) refuses to deal with numbers that cannot be represented as floats. In order to avoid interoperability problems, let's use an advance value of `1e37`, which can be represented even by 32-bit floats and works equally well enough in practice as an "infinite" value.
I'm well aware of the limitations of floating point numbers. The value is used precisely because it is translated into infinity by the game. Not just a huge number, but true infinity. Because of this, a change to a smaller value would introduce a change in behavior, which could be problematic for some users. Interoperability has historically not been a big concern since the behavior of the game is fully known and the few tools I've encountered that deal with Minecraft fonts have not displayed problems with it. I want to explore what can and should be done before merging this. For example, what if the value was isolated to its own file? |
Thanks for taking a look at the PR! 😄
Yeah, I figured that such a huge value would be rounded to infinity by the game. Still, as outlined above, relying on a specific JSON parser behavior is hacky, and Minecraft has a history of updating and completely changing the libraries it uses to parse things. For example, as recently as the 1.20.5 release, the library used to read Ogg Vorbis files changed. While it's arguably less likely that the JSON parser will be significantly changed, given how widespread the overall reliance on Gson's lenient behavior is, I'd still consider it a real possibility.
While this is technically true, I've been suggesting PackSquash users try replacing the problematic value with 1e37 for some time now, and I've never heard of it causing them any problems. Also,
I'm down to explore stuff too! However, I'm afraid that isolating this value in a separate font JSON file would just move the problem to that file, not really fix it. On the other hand, changing |
(I don't consider packs having a slim chance of breaking in future versions to be a concern. The resource pack format changes slightly every version anyway, making it an unwinnable battle. We now also have the option of presenting different versions of files to different versions of the game.) If isolating it to it's own JSON file and setting it up to be ignored on your end isn't an option, I think I'd rather just take it out. I can put in a new character that is huge but not infinite. |
Fair enough. I'd still advocate trying to avoid dependencies on specific implementation details as much as possible to make life easier when upgrading, but I also understand that specific decisions on the matter mostly come down to personal considerations of workflow and perceived breakage probability and impact.
Yes, as far as I know that would be the best option. Nevertheless, despite my lack of evidence that an advance of Would it help if I reached out to affected users to gather explicit feedback on how an advancement of |
I was just reminded about this PR when a new person joined my Discord server and shared their wishes on seeing it merged… 😂 I'm curious whether there are any remaining tasks or changes needed here? Would it be enough to update the |
The
default.json
font file contains a font advance value of1e400
. This value is too large to be represented as-is even by IEEE 754 64-bit floating point numbers as used by Java and, by extension, Minecraft. Gson, the JSON deserialization library used by Minecraft, cannot properly represent such a number either, but the deserialization process is lenient and chugs along with a practically close enough value.According to the ECMA JSON standard, numbers in JSON can be arbitrarily large, so such a number is technically within the specification. However, the standard points out that different programs may disagree on how to represent numbers, which can lead to interoperability problems in practice:
On the other hand, IETF RFC 7159, another JSON standard, states:
Besides with Minecraft itself, one such interoperability problem occurs with PackSquash, which relies on
serde_json
for JSON parsing, and that parser (rightly) refuses to handle numbers that cannot be represented as floats.To avoid interoperability problems, let's use an advance value of
1e37
, which can be represented even by 32-bit floats and works just as well in practice as an "infinite" value.