fix(android): cold-launch NPE guard + root cause & fix for the #15 mod crashes (runtime fix: N64ModernRuntime#1) - #20
Open
Rival wants to merge 1 commit into
Open
Conversation
On some OEM Android 16 builds (observed on ColorOS 16, Oppo Find N6)
PhoneWindow.getInsetsController() throws an internal NPE when called
from onCreate() before the DecorView is attached to the window,
crashing every cold launch of a freshly installed build:
java.lang.NullPointerException
at com.android.internal.policy.PhoneWindow.getInsetsController
at BanjoSDLActivity.applyImmersiveFullscreen(BanjoSDLActivity.java:284)
at BanjoSDLActivity.onCreate
Wrap the call in a NullPointerException guard: fullscreen is retried
from onResume()/onWindowFocusChanged() once the decor view exists, so
skipping here only defers it.
Author
|
Heads-up on the red checks: they all fail in ~5s at the checkout step with i.e. this is GitHub's fork-checkout guard inside The change itself is a 10-line Java guard; happy to rebase/retest in any form you prefer. |
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.
Summary
Small launcher fix, plus the diagnosis + fix for the "every code mod crashes on Android" issue reported in #15 (the actual fixes live in the runtime submodule — see the companion PR).
This PR
applyImmersiveFullscreen()crashed every cold launch of a freshly installed build on ColorOS 16 / Android 16 (Oppo Find N6):PhoneWindow.getInsetsController()throws an internal NPE when called fromonCreate()before the DecorView is attached. Guarded with aNullPointerExceptioncatch — fullscreen is re-applied fromonResume()/onWindowFocusChanged()once the view exists, so nothing is lost, only deferred.The mod-loading crashes from #15 — root cause + fix
We reproduced and instrumented this on-device. All code mods (
.nrm) crashed at startup withSIGSEGV (SEGV_ACCERR)— trying to execute non-executable memory — while.rtztexture packs worked. Raw evidence:Instrumenting
librecomp'sunprotect()/protect()showedprotect()returningEACCESfor every hooked page: on Android anuntrusted_appprocess cannot regainPROT_EXECon a file-backed page aftermprotect()dirtied it withPROT_WRITE(SELinuxexecmod). The page stayed read-write and the first branch into the hooked function faulted. On desktop Linux there is no such policy — which is why the PC builds are unaffected.Fix (in the N64ModernRuntime submodule): swap each patched page for a fresh anonymous page at the same address via
mremap(MREMAP_FIXED)(anonymousPROT_EXECis what JIT relies on), with an mprotect fallback. Plus two sibling issues found on the way:Numberconfig options (TSRStormed-FasterTransitions, FOVSlider) were rejected asInvalid mod— strictget_ptr<int64_t*>vs nlohmann'snumber_unsigned; cherry-picked the upstream fix.➡️ Runtime PR: AurelioB/N64ModernRuntime#1 — merge that first, then bump the submodule pointer here.
With both applied, on-device verification: all previously-crashing mod sets install and play (52 hooked pages, all
rc=0, zeroSIGSEGV).Build notes (no code changes — for whoever builds the port from source)
SDLActivity.javahard-checks the native version and shows a fatal "SDL C/Java version mismatch" otherwise.lib/rt64'sfile_to_chost tool isn't cross-compile-aware — build a host-native copy and put it onPATH(same pattern as the existingld.lldsymlink).validateAndroidBuildEnvironmentgate only checks that some clang/ld.lld is on PATH: a newer system clang works (needs-Wno-error=incompatible-pointer-typesforpatches/).extra/inputs repo is only needed forbanjo.us.v10.decompressed.z64, which can be reproduced locally from the checksum-verified US 1.0 ROM by buildinglib/bk-decomp'sdecompressed.us.v10.z64target.Closes #15 (the crash itself; the browser-download quirk some users hit is separate).