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

Byte sizes need to be parsed with invariant culture #3

Merged
merged 1 commit into from
Mar 10, 2022

Conversation

zsoi
Copy link
Contributor

@zsoi zsoi commented Mar 8, 2022

On systems using a different locale than english, the default locale used to parse floats can produce incorrect numbers from a english-written build layout, e.g. 81.27kb may be parsed as 8127 kb with a german locale.

To prevent this from happening, machine-readable numbers should always be written and parsed with the InvariantCulture. This gives reproducible results regardless of the active locale on the thread.

This change just adds the InvariantLocale onto the float.Parse() invocations for sizes.

…rrect "invariant" number format that unity usually spits out
@pschraut
Copy link
Owner

pschraut commented Mar 8, 2022

Thank you for looking into issue #1 and the PR 👍

While the number parsing itself is fixed with your PR, the underlying problem remains unfortunately. Perhaps you have an idea how to fix it.

The problem is that Addressables stores numbers using a comma in a comma-separated list. This makes it unreliable to split the list-items from actual numbers, because the comma is used for different things.

Here is an example:
Archive test.bundle (Size: 1,79KB, Compression: Lz4HC, Asset Bundle Object Size: 280B)

The list-items or pairs are actually:

  • Size: 1,79KB
  • Compression: Lz4HC
  • Asset Bundle Object Size: 280B

You can think of what's in-front of the colon as key (i.e. "Size") and what's on the other side as value (i.e. "1,79KB"). The code that parses this list can be found in BuildLayout.cs in the ReadAttributes method.

Since Size: 1,79KB contains a comma, the code handles the pairs more like this instead:

  • Size
  • 1
  • 79KB
  • Compression: Lz4HC
  • Asset Bundle Object Size: 280B

Everything else in Unity is serializing its data using an English locale, but Addressables for some reason isn't. Maybe this can be avoided by adding some trickery to the ReadAttributes code, but I was running out of ideas.

@zsoi
Copy link
Contributor Author

zsoi commented Mar 8, 2022

As mentioned in #1 this can be easily fixed with a custom fork of the addressables package. I filed a bug report with Unity and they may address this issue in a next release but from what I've heard they will scrap the textual build layout format for good in the next minor release and go with something more machine-readable by default.

@pschraut pschraut merged commit edd140d into pschraut:master Mar 10, 2022
@pschraut
Copy link
Owner

Oh sorry, I didn't see your comment in the issue before. Yes, makes sense. Thank you for the PR!

@gustavopsantos
Copy link

@pschraut Cant we use ', ' (comma + space) as a delimiter to parse the separated values? This way we would separate was is number and what is CSV delimiter.

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

Successfully merging this pull request may close these issues.

3 participants