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

Do not query guest version from UI thread #1949

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changed:

Fixed:
- Work around a problem with our memory-leak fix where our old LazyList code would crash when its placeholders were unexpectedly removed.
- Avoid calling into the internal Zipline instance from the UI thread on startup. This would manifest as weird native crashes due to multiple threads mutating shared memory.


## [0.10.0] - 2024-04-05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import app.cash.zipline.Zipline
import app.cash.zipline.ZiplineApiMismatchException
import app.cash.zipline.ZiplineScope
import app.cash.zipline.withScope
import kotlin.concurrent.Volatile
import kotlinx.coroutines.CoroutineScope
import kotlinx.serialization.json.Json

Expand All @@ -37,22 +38,26 @@ internal class ZiplineCodeSession<A : AppService>(
appService = appService,
) {
private val ziplineScope = ZiplineScope()
private lateinit var appLifecycle: AppLifecycle

override val json: Json
get() = zipline.json

override val guestProtocolVersion: RedwoodVersion
get() {
return try {
appLifecycle.guestProtocolVersion
} catch (_: ZiplineApiMismatchException) {
RedwoodVersion.Unknown
}
@Volatile
private var _guestProtocolVersion: RedwoodVersion? = null

override val guestProtocolVersion: RedwoodVersion get() =
checkNotNull(_guestProtocolVersion) {
"Cannot access guest version before ziplineStart"
}

override fun ziplineStart() {
appLifecycle = appService.withScope(ziplineScope).appLifecycle
val appLifecycle = appService.withScope(ziplineScope).appLifecycle

_guestProtocolVersion = try {
appLifecycle.guestProtocolVersion
} catch (_: ZiplineApiMismatchException) {
RedwoodVersion.Unknown
}

val host = RealAppLifecycleHost(
appLifecycle = appLifecycle,
Expand Down