Fix race condition in player#2750
Conversation
fire-light42
left a comment
There was a problem hiding this comment.
- Please change currentLinks+currentSubs to ConsistentLiveData if you want to do this.
- Please see filterSubByLang.
I think I did what you mean? |
|
@fire-light42 I wonder if you could also perhaps explain to me a little bit what ConsistentLiveData does and when it should be used? I'm having a hard time understanding it's code, but am curious at least when it is something that should be used. |
ConsistentLiveData is used to avoid the threading issue with LiveData. To be more precise, LiveData is "thread-safe", but only makes its value "visible" after it writes the value in the main thread. This means that: ConsistentLiveData is simply a LiveData with a backing volatile variable, so it becomes visible immediately when using In general you should never have to use .value given that observe should only be used for UI. However, to solve this problem we use ConsistentLiveData to solve thread issues whenever we need to access .value. |
|
That makes a ton of sense and I really appreciate you taking the time for the explanation, thanks a ton for that and it will be helpful for me in the future I think. |
|
I think I may have a better way to do thia soon that fixes the underlying issue in the view model rather than relying on this before startPlayer. I am testing and will let you know if this method should be merged or not once I see if it is going to work well. My way fixes a bunch of race conditions and allows full process death restoration and fixes numerous other bugs also. I am just mentioning here so this shouldnt be merged yet if this works out. I will update here within a couple days. |
|
@fire-light42 there is a very easy much better fix for this I will push later. |
Fixes #2746
I was unable to reproduce the issue after this, but also it doesn't happen every single time anyway so I can not be 100% certain this fully fixes it, though seemed to.