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

Crash in rxJavaExample #5659

Open
myproject opened this issue Jan 4, 2018 · 3 comments
Open

Crash in rxJavaExample #5659

myproject opened this issue Jan 4, 2018 · 3 comments

Comments

@myproject
Copy link

myproject commented Jan 4, 2018

clone Latest Realm Examples and Run rxJavaExample -> ANIMATION activity.

just wait for about 2-3 minutes ,then Crash:

io.realm.examples.rxjava E/AndroidRuntime: FATAL EXCEPTION: RxComputationThreadPool-1
                                                                      Process: io.realm.examples.rxjava, PID: 14058
                                                                      java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created.
                                                                          at io.realm.BaseRealm.checkIfValid(BaseRealm.java:426)
                                                                          at io.realm.RealmResults.checkForAddRemoveListener(RealmResults.java:220)
                                                                          at io.realm.RealmResults.removeChangeListener(RealmResults.java:244)
                                                                          at io.realm.rx.RealmObservableFactory$6$2.run(RealmObservableFactory.java:171)
                                                                          at io.reactivex.disposables.RunnableDisposable.onDisposed(RunnableDisposable.java:30)
                                                                          at io.reactivex.disposables.RunnableDisposable.onDisposed(RunnableDisposable.java:20)
                                                                          at io.reactivex.disposables.ReferenceDisposable.dispose(ReferenceDisposable.java:43)
                                                                          at io.reactivex.internal.disposables.DisposableHelper.dispose(DisposableHelper.java:125)
                                                                          at io.reactivex.internal.disposables.SequentialDisposable.dispose(SequentialDisposable.java:73)
                                                                          at io.reactivex.internal.operators.flowable.FlowableCreate$BaseEmitter.cancel(FlowableCreate.java:276)
                                                                          at io.reactivex.internal.operators.flowable.FlowableFlatMap$MergeSubscriber.cancel(FlowableFlatMap.java:353)
                                                                          at io.reactivex.internal.subscriptions.SubscriptionHelper.cancel(SubscriptionHelper.java:189)
                                                                          at io.reactivex.internal.operators.flowable.FlowableZip$ZipSubscriber.cancel(FlowableZip.java:399)
                                                                          at io.reactivex.internal.operators.flowable.FlowableZip$ZipCoordinator.cancelAll(FlowableZip.java:159)
                                                                          at io.reactivex.internal.operators.flowable.FlowableZip$ZipCoordinator.drain(FlowableZip.java:188)
                                                                          at io.reactivex.internal.operators.flowable.FlowableZip$ZipCoordinator.error(FlowableZip.java:151)
                                                                          at io.reactivex.internal.operators.flowable.FlowableZip$ZipSubscriber.onError(FlowableZip.java:388)
                                                                          at io.reactivex.internal.operators.flowable.FlowableInterval$IntervalSubscriber.run(FlowableInterval.java:87)
                                                                          at io.reactivex.internal.schedulers.ScheduledDirectPeriodicTask.run(ScheduledDirectPeriodicTask.java:39)
                                                                          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
                                                                          at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:278)
                                                                          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:273)
                                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                          at java.lang.Thread.run(Thread.java:761)
@Zhuinden
Copy link
Contributor

Zhuinden commented Jan 4, 2018

I guess

.zipWith(Flowable.interval(1, TimeUnit.SECONDS), (person, tick) -> person)

Changes the unsubscribe thread to RxComputation scheduler.

Adding subscribeOn(AndroidSchedulers.mainThread()).unsubscribeOn(AndroidSchedulers.mainThread()) after asFlowable() would fix it.

@myproject
Copy link
Author

@Zhuinden thank you.
It works!
And add onError handling or BackpressureStrategy better!

@cmelchior
Copy link
Contributor

Ups. Yes, we should fix that.

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

No branches or pull requests

5 participants