Skip to content

Fix crash when rotating shape/trace screen#7068

Merged
grzesiek2010 merged 6 commits intogetodk:masterfrom
seadowg:osm-crash
Feb 3, 2026
Merged

Fix crash when rotating shape/trace screen#7068
grzesiek2010 merged 6 commits intogetodk:masterfrom
seadowg:osm-crash

Conversation

@seadowg
Copy link
Member

@seadowg seadowg commented Feb 2, 2026

Closes #7066

Why is this the best possible solution? Were any other approaches considered?

There were a couple of features of the code that causes this issue:

  1. The invalidMessage object passed to GeoPolyFragment was the product of LiveData which had been created via a map that referenced getString - implicitly requiring the Fragment where it was executed.
  2. That LiveData is then passed to a ViewModel meaning it would be retained between configuration changes - the "original" instance would be reused, and the new one created as part of recreation would effectively be ignored

Combining 1 with 2 gets you a crash as re-executing the map operation after recreation requires a Fragment that's been destroyed.

1 was definitely an issue - map operations should never have side-effects and shouldn't rely on life-cycleable objects. I did also consider changing 2, but alternatives (like using a mediator that both ViewModels could share) felt over-architected. I think this is just a quirk of any stateful view component (be it a Fragment or a Composable or a View): initial state will be ignored when the component is recreated.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Should just fix the issue. No maps code has been touched.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

val validationResult = it.value
if (validationResult is FailedValidationResult && validationResult.index == prompt.index) {
validationResult.customErrorMessage ?: getString(validationResult.defaultErrorMessage)
if (it is FailedValidationResult && it.index == prompt.index) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grzesiek2010 I don't think we need the index check here any longer right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems to be redundant now.


import android.content.Context

sealed class DisplayString {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grzesiek2010 please let me know if I've already created this abstraction! I've definitely used it on other Android projects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember anything like that.

@seadowg seadowg marked this pull request as ready for review February 3, 2026 11:39
@seadowg seadowg requested a review from grzesiek2010 February 3, 2026 11:39
@seadowg seadowg requested a review from grzesiek2010 February 3, 2026 12:50
@grzesiek2010 grzesiek2010 merged commit 3a1f5b8 into getodk:master Feb 3, 2026
7 checks passed
@seadowg seadowg deleted the osm-crash branch February 3, 2026 13:40
@dbemke
Copy link

dbemke commented Feb 4, 2026

Tested with Success!

Verified on Android 10

Verified cases:

@srujner
Copy link

srujner commented Feb 4, 2026

Tested with Success!

Verified on Android 14

@WKobus
Copy link

WKobus commented Feb 4, 2026

Tested with success

Verified on Android 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash on OSM after rotating the screen with incremental=true

5 participants