Giter Site home page Giter Site logo

[BUG] Sextant sample navigation crashes with Android.Util.AndroidRuntimeException: 'Animators may only be run on Looper threads' about sextant HOT 8 CLOSED

winterdouglas avatar winterdouglas commented on April 27, 2024
[BUG] Sextant sample navigation crashes with Android.Util.AndroidRuntimeException: 'Animators may only be run on Looper threads'

from sextant.

Comments (8)

RLittlesII avatar RLittlesII commented on April 27, 2024 1

@winterdouglas Thanks for looking into this issue and the detailed report.

from sextant.

open-collective-bot avatar open-collective-bot commented on April 27, 2024

Hey @winterdouglas 👋,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider contributing financially.

https://opencollective.com/reactiveui

PS.: We offer priority support for all financial contributors. Don't forget to add priority label once you start contributing 😄

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!

from sextant.

winterdouglas avatar winterdouglas commented on April 27, 2024

I did a backtracking investigation already as follows:

Versions of libraries

  • Xamarin.Forms 4.2.0.910310
  • ReactiveUI.XamForms 10.5.43
    • System.Reactive 4.3.1
  • Android Support 28.0.0.3

Investigation step by step

  • Navigating by using the Navigation from the page itself works nicely
  • Changing the ReactiveCommand with an ICommand: the issue doesn't happen anymore
  • At this point I can conclude that the navigation is not the issue but something related to RxUI, Rx.Net or Xamarin.Forms
  • Next downgrading RxUI to the latest 9.x (9.22.1): The issue to go away
  • Just to make sure it's not Xamarin.Forms I manually changed the version of Xamarin to the initial one mentioned above (4.2.0.910310): The issue still persists
  • Downgrading RxUI to 10.5.31: Same results
  • Downgrading RxUI down to the version 10.1.7: Same results (checked on 10.5.7, 10.2.2, 10.1.7)
  • RxUI 10.1.5: Gives me another exception: System.TypeInitializationException: 'The type initializer for 'ReactiveUI.RxApp' threw an exception.'
  • RxUI 10.1.1: The error above happens on this version too
  • RxUI 10.0.1: Here it works again
  • RxUI 9.22.1: Works as well

All the above steps were performed with clean and rebuilt project + the app being reinstalled (uninstall/redeploy)

Apparently the issue started from the version 10.1.1 on, the only change from the version 10.0.1 to 10.1.1 is the update of Mono.Android on the following commit:
reactiveui/ReactiveUI@c4be8bc

from sextant.

winterdouglas avatar winterdouglas commented on April 27, 2024

Relates to:
#reactiveui/ReactiveUI/issues/2170

from sextant.

winterdouglas avatar winterdouglas commented on April 27, 2024

I did another round of investigation here and so far I'd say the issue is really related to the command's IsExecuting.

var canExecute = Observable
    .Return(false)
    .Delay(TimeSpan.FromSeconds(5), RxApp.TaskpoolScheduler)
    .StartWith(true)
    .ObserveOn(RxApp.MainThreadScheduler);

PushPage = ReactiveCommand
    .CreateFromObservable(() =>
        Observable.Return(Unit.Default),
        canExecute,
        outputScheduler: RxApp.MainThreadScheduler);

I can reproduce the issue with this code above. As you can see the command does nothing and the only thing that happens there is the command's canExecute being initialized as true and after 5 seconds going to false, that's enough to make the app to crash.
I could conclude also that the issue happens only when there's an UI element bound to the command, in this case a button.

from sextant.

winterdouglas avatar winterdouglas commented on April 27, 2024

Going a bit further with the investigation I could find that by doing the following on the view itself, the code actually breaks as well, so the real issue is not on the command's IsExecuting but on the RxApp.MainThreadScheduler that's actually not really the main thread.
In the code below the isMain will be false by using the latest RxUI version (10.5.43), so when the button's IsEnabled is set, that's not happening on the main thread.

Observable
    .Return(false)
    .Delay(TimeSpan.FromSeconds(5), RxApp.TaskpoolScheduler)
    .ObserveOn(RxApp.MainThreadScheduler)
    .Subscribe(x =>
    {
        var isMain = Xamarin.Essentials.MainThread.IsMainThread;
        PushPage.IsEnabled = x;
    });

I'm gonna create a sample with these cases and some unit tests as @RLittlesII suggested.

from sextant.

winterdouglas avatar winterdouglas commented on April 27, 2024

Ok, I now created a completely clean project with only ReactiveUI and put the exact same package versions and the code as above, I couldn't reproduce the issue anymore!

Looking further what could be the difference among them I could now find the real issue, it happens because on the Sextant sample the target/compile framework for the Android project is Android 8.1 while in the newly created one is Android 9, that makes the difference.
I noticed that when the project targets Android 8.1 a DefaultScheduler is resolved while when targeting Android 9 the correct scheduler is resolved.

Sextant sample (compiled using Android 8.1)
sextant-sample

Clean sample (compiled using Android 9)
clean-sample

from sextant.

RLittlesII avatar RLittlesII commented on April 27, 2024

Resolved By: #172

from sextant.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.