summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-18 23:32:33 -1000
committerPeter Stone <thepeterstone@gmail.com>2026-03-18 23:32:33 -1000
commit2052c40b2b8914cd0965c80bc504c86766d20443 (patch)
tree5a8cfe5278f795279b40d4d6910f33312c1dba95
parent4d637d284dce6fc674599c226dd063c442fd350f (diff)
fix: rasterize anchor icon vector drawable to prevent startup crash
BitmapFactory.decodeResource returns null for XML vector drawables. Passing null to MapLibre's style.addImage caused a NPE that propagated through JNI as PendingJavaException, crashing the app on every launch. Fix uses ContextCompat.getDrawable + Canvas rasterization, matching the pattern already used in setupTidalCurrentMapLayers. Also upgrades MapLibre Android SDK from 11.5.1 to 13.0.1. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--android-app/app/build.gradle2
-rw-r--r--android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt14
2 files changed, 13 insertions, 3 deletions
diff --git a/android-app/app/build.gradle b/android-app/app/build.gradle
index 0d5703d..7e5ab0f 100644
--- a/android-app/app/build.gradle
+++ b/android-app/app/build.gradle
@@ -88,7 +88,7 @@ dependencies {
implementation 'com.google.android.gms:play-services-location:21.2.0'
// Map
- implementation 'org.maplibre.gl:android-sdk:11.5.1'
+ implementation 'org.maplibre.gl:android-sdk:13.0.1'
// Testing
testImplementation 'junit:junit:4.13.2'
diff --git a/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt b/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
index a3eebfc..79758f0 100644
--- a/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
+++ b/android-app/app/src/main/kotlin/org/terst/nav/MainActivity.kt
@@ -475,8 +475,18 @@ class MainActivity : AppCompatActivity() {
private fun setupAnchorMapLayers(style: Style) {
- // Add anchor icon
- style.addImage(ANCHOR_ICON_ID, BitmapFactory.decodeResource(resources, R.drawable.ic_anchor))
+ // Add anchor icon (rasterise vector drawable — BitmapFactory returns null for VDs)
+ val anchorDrawable = ContextCompat.getDrawable(this, R.drawable.ic_anchor) ?: return
+ val anchorBitmap = Bitmap.createBitmap(
+ anchorDrawable.intrinsicWidth.coerceAtLeast(24),
+ anchorDrawable.intrinsicHeight.coerceAtLeast(24),
+ Bitmap.Config.ARGB_8888
+ )
+ Canvas(anchorBitmap).also { canvas ->
+ anchorDrawable.setBounds(0, 0, canvas.width, canvas.height)
+ anchorDrawable.draw(canvas)
+ }
+ style.addImage(ANCHOR_ICON_ID, anchorBitmap)
// Create sources
anchorPointSource = GeoJsonSource(ANCHOR_POINT_SOURCE_ID)