Skip to content

Unexpected Vector3 sum on Android #114094

Open
@MartinZikmund

Description

@MartinZikmund

Description

I encountered a very odd behavior where Vector3 sum is invalid on Android under very specific circumstances.

Consider the following method, which logs the value of total variable and then returns the exact same sum in return statement.

private Vector3 GetTotalOffset()
{
    if (IsTranslationEnabled && Properties.TryGetVector3("Translation", out var translation) == CompositionGetValueStatus.Success)
    {
        var total = Offset + translation;
        UIDebugLog.Log($"Total: {total}");

        return (Offset + translation);
    }

    return Offset;
}

This method is used as follows:

var totalOffset = GetTotalOffset();
if (IsRefresh)
{
    UIDebugLog.Log($"Total2: {totalOffset}");
}

Technically the Total1 and Total2 values should have the exact same value. Surprisingly, this is the case only in debug mode with debugger attached:

Image

However, in Release mode or in Debug mode without debugger attached we are getting invalid results from the return statement:

Image

Reproduction Steps

  1. Clone unoplatform/uno@af0a060
  2. Rename src\crosstargeting_override.props.sample to src\crosstargeting_override.props
  3. Inside this file, uncomment UnoTargetFrameworkOverride and change it to <UnoTargetFrameworkOverride>net9.0-android</UnoTargetFrameworkOverride>
  4. Open src\Uno.UI-Skia-only.slnf
  5. Run SamplesApp.Skia.netcoremobile with debugger attached
  6. Search for RefreshContainerNavigation sample and open it
  7. Note the refresh container behaves as expected - the indicator only shows up when the list is pulled down
  8. Note the logged Total1 and Total2 values in the bottom are equal
  9. Stop debugging and open the app again without debugger
  10. Navigate to the RefreshContainerNavigation sample
  11. Note the refresh indicator is misaligned
  12. Note the logged Total1 and Total2 values in the bottom are not equal

Expected behavior

Sum of Vector3 values should be reliable.

Actual behavior

Sum of Vector3 values differs when done within a local variable vs. within a return statement on Android.

Regression?

No response

Known Workarounds

Perform the sum manually, per vector element.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions