Draft
fix: prevent crash on _activeTheme access before ThemeManager initialization#2070
_activeTheme access before ThemeManager initialization#2070Conversation
Copilot
AI
changed the title
[WIP] Fix crash when switching to trime due to uninitialized _activeTheme
fix: prevent crash on Aug 11, 2026
_activeTheme access before ThemeManager initialization
There was a problem hiding this comment.
Pull request overview
Prevents an UninitializedPropertyAccessException crash when Android calls onCreateInputView() before ThemeManager.init() finishes (e.g., after long inactivity), by adding an explicit initialization check and deferring input-view creation until the theme is ready.
Changes:
- Add
ThemeManager.isInitializedto safely detect whether_activeThemehas been set. - Guard
TrimeInputMethodService.onCreateInputView()to return early when the theme isn’t ready and set a pending flag. - After
ThemeManager.init()completes in the Rime-ready block, trigger a deferredreplaceInputViews()if input view creation was previously requested.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt | Defers input-view creation until theme initialization completes, then replays the creation if needed. |
| app/src/main/java/com/osfans/trime/data/theme/ThemeManager.kt | Exposes a safe isInitialized check for _activeTheme to avoid lateinit access crashes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
When the IME is reattached after being idle for a long time, Android may call onCreateInputView() before ThemeManager.init() completes (which runs asynchronously after Rime is ready). This caused an UninitializedPropertyAccessException on _activeTheme. Fix: Add ThemeManager.isInitialized property, check it in onCreateInputView() and defer view creation via inputViewPending flag. After ThemeManager.init() completes, create input views if pending. Closes #2058 Co-authored-by: Bambooin <7157227+Bambooin@users.noreply.github.com>
Bambooin
force-pushed
the
copilot/fix-crash-when-switching-to-trime
branch
from
August 11, 2026 13:59
5dedf1e to
577b718
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After prolonged inactivity, Android may call
onCreateInputView()beforeThemeManager.init()completes — the init runs in a coroutine suspended until Rime is ready, creating a race where_activeTheme(lateinit) is accessed uninitialized, crashing withUninitializedPropertyAccessException.Changes
ThemeManager— exposeisInitialized: Booleanvia::_activeTheme.isInitializedto allow safe pre-init checksTrimeInputMethodService— addinputViewPending: Booleanflag; guardonCreateInputView()to bail early (returningnull) if theme isn't ready yet, and afterThemeManager.init()completes in the async Rime-ready block, trigger deferredreplaceInputViews()if the flag is set: