game-activity: tolerate the NULL pre-IME GameTextInput buffer - #252
Open
mudbungie wants to merge 1 commit into
Open
game-activity: tolerate the NULL pre-IME GameTextInput buffer#252mudbungie wants to merge 1 commit into
mudbungie wants to merge 1 commit into
Conversation
GameTextInput's initial state, delivered before the IME has attached, carries a NULL text pointer with length 0. The conversion callback fed it straight to slice::from_raw_parts, which requires a non-null pointer even for an empty slice: undefined behavior in release builds, and under debug_assertions the standard library's precondition check aborts the process (a non-unwinding panic inside an extern "C" callback) on the first frame of every debug build using the game-activity backend. Treat the NULL buffer as the empty text it represents.
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.
The defect
GameTextInputdelivers its initial state — before the IME has attached —with a NULL
text_UTF8pointer andtext_length == 0.map_input_state_to_text_event_callbackfeeds that pointer straight tostd::slice::from_raw_parts, whose contract requires a non-null pointereven for a zero-length slice. That is undefined behavior in release builds,
and under
debug_assertionsthe standard library's precondition checkfires: a non-unwinding panic inside an
extern "C"callback, i.e. animmediate abort.
Observed
Every debug build of a
game-activity-backend app closes on its firstframe (observed with android-activity 0.6.1 + androidx games-activity
4.4.0, egui/winit app, current-generation Pixel, SDK 35). The tombstone
points at the stdlib's
from_raw_partsprecondition inside the callback.Release builds compile the check out and happen to survive the len-0 read,
which makes the failure look like a debug-only mystery rather than what it
is — UB reached on every launch.
The fix
Treat the NULL buffer as the empty text it represents before constructing
the slice. One guard, no behavior change for any non-null buffer.