Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Android crash when canceling downloading offline map twice #9858

Closed
prompteus opened this issue Aug 25, 2017 · 1 comment · Fixed by #9967
Closed

Android crash when canceling downloading offline map twice #9858

prompteus opened this issue Aug 25, 2017 · 1 comment · Fixed by #9967
Labels
Android Mapbox Maps SDK for Android crash offline

Comments

@prompteus
Copy link

Android
Mapbox SDK version: 5.1.3

(I use Kotlin but I hope you get the idea)

Steps to trigger behavior

My code looks like this:

fun downloadMapToOffline() {
	downloadProgressPercentage.set(0)
	downloadStatus.set(OfflineMapStatus.DOWNLOADING)

	val offlineRegionDefinition = OfflineTilePyramidRegionDefinition(
			MAPBOX_STYLE_URL,
			CZECH_REPUBLIC_BOUNDS,
			OFFLINE_MIN_ZOOM,
			OFFLINE_MAX_ZOOM,
			this.resources.displayMetrics.density)

	offlineManager.createOfflineRegionAsync(offlineRegionDefinition) { offlineRegion ->
		regionBeingDownloaded = offlineRegion
		offlineRegion.setDownloadState(STATE_ACTIVE)
		startProgress()

		offlineRegion.observeDownloadChange { status ->
			if (status.isComplete) {
				endProgress()
			} else if (status.isRequiredResourceCountPrecise) {
				downloadProgressPercentage.set(status.completedResourceCount intPercentageOf status.requiredResourceCount)
			}
		}
	}
}

private fun stopDownloading() {
	downloadStatus.set(STOPPING_DOWNLOAD)
	defaultSharedPreferences
			.edit()
			.putBoolean(KEY_MAP_IS_OFFLINE, false)
			.apply()
	regionBeingDownloaded?.setDownloadState(OfflineRegion.STATE_INACTIVE)
	downloadProgressPercentage.set(0)
	offlineManager.listOfflineRegionsAsync {
		if (it.isNotEmpty()) {
			it[0].deleteAsync {
			    downloadProgressPercentage.set(0)
			    downloadStatus.set(NO_DOWNLOADED_MAP)
			}
		}
	}
}

When stopDownloading() is called twice very quickly, so I call offline region delete method when it is already being deleted it throws C++ exception:

08-25 10:27:14.911 26797-26872/cz.fmm.utajenaobrana A/libc: /usr/local/google/buildbot/src/android/ndk-r13-release/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:74: void abort_message(const char *, ...): assertion "terminating with uncaught exception of type std::runtime_error: Malformed offline region definition" failed
08-25 10:27:14.912 26797-26872/cz.fmm.utajenaobrana A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 26872 (DefaultFileSour)
08-25 10:27:15.018 201-201/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-25 10:27:15.019 201-201/? A/DEBUG: Build fingerprint: 'google/hammerhead/hammerhead:6.0.1/M4B30Z/3437181:user/release-keys'
08-25 10:27:15.019 201-201/? A/DEBUG: Revision: '11'
08-25 10:27:15.019 201-201/? A/DEBUG: ABI: 'arm'
08-25 10:27:15.019 201-201/? A/DEBUG: pid: 26797, tid: 26872, name: DefaultFileSour  >>> cz.fmm.utajenaobrana <<<
08-25 10:27:15.019 201-201/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
08-25 10:27:15.048 201-201/? A/DEBUG: Abort message: '/usr/local/google/buildbot/src/android/ndk-r13-release/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:74: void abort_message(const char *, ...): assertion "terminating with uncaught exception of type std::runtime_error: Malformed offline region definition" failed'
08-25 10:27:15.049 201-201/? A/DEBUG:     r0 00000000  r1 000068f8  r2 00000006  r3 a0d1c978
08-25 10:27:15.049 201-201/? A/DEBUG:     r4 a0d1c980  r5 a0d1c930  r6 00000002  r7 0000010c
08-25 10:27:15.049 201-201/? A/DEBUG:     r8 a1205c01  r9 a0d1c814  sl a0d1c860  fp a103a11d
08-25 10:27:15.049 201-201/? A/DEBUG:     ip 00000006  sp a0d1c0b0  lr b6ccbb61  pc b6ccdf50  cpsr 400e0010
08-25 10:27:15.079 201-201/? A/DEBUG: backtrace:
08-25 10:27:15.079 201-201/? A/DEBUG:     #00 pc 00041f50  /system/lib/libc.so (tgkill+12)
08-25 10:27:15.079 201-201/? A/DEBUG:     #01 pc 0003fb5d  /system/lib/libc.so (pthread_kill+32)
08-25 10:27:15.079 201-201/? A/DEBUG:     #02 pc 0001c30f  /system/lib/libc.so (raise+10)
08-25 10:27:15.079 201-201/? A/DEBUG:     #03 pc 000194c1  /system/lib/libc.so (__libc_android_abort+34)
08-25 10:27:15.079 201-201/? A/DEBUG:     #04 pc 000174ac  /system/lib/libc.so (abort+4)
08-25 10:27:15.079 201-201/? A/DEBUG:     #05 pc 0001af23  /system/lib/libc.so (__libc_fatal+16)
08-25 10:27:15.079 201-201/? A/DEBUG:     #06 pc 00019549  /system/lib/libc.so (__assert2+20)
08-25 10:27:15.080 201-201/? A/DEBUG:     #07 pc 002eacbd  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #08 pc 002ead81  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #09 pc 002e9575  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #10 pc 002e9101  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #11 pc 0012743b  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #12 pc 0012a315  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #13 pc 0011e65d  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #14 pc 0011e335  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #15 pc 00124037  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #16 pc 00123fef  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #17 pc 00117e89  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #18 pc 00117dd9  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #19 pc 0011f1c5  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.080 201-201/? A/DEBUG:     #20 pc 0011f147  /data/app/cz.fmm.utajenaobrana-1/lib/arm/libmapbox-gl.so
08-25 10:27:15.081 201-201/? A/DEBUG:     #21 pc 0003f45f  /system/lib/libc.so (_ZL15__pthread_startPv+30)
08-25 10:27:15.081 201-201/? A/DEBUG:     #22 pc 00019b43  /system/lib/libc.so (__start_thread+6)

Expected behavior

Mapbox should catch C++ exception and throw Java exception so we can catch it inside of Android java code. somehow like this (in my kotlin code):

offlineManager.listOfflineRegionsAsync {
    try {
         if (it.isNotEmpty()) {
               it[0].deleteAsync {
                downloadProgressPercentage.set(0)
                    downloadStatus.set(NO_DOWNLOADED_MAP)
         }
     }
    } catch (e: MalformedOfflineRegionException) {
         ....
    }
}

or like this in java in your callback system:
offlineRegion.delete(object : OfflineRegion.OfflineRegionDeleteCallback {
override fun onDelete() {
...
}

    override fun onError(error: String?) {
         .... // error could now be MalformedOfflineRegionException
    }

})

Actual behavior

App crashes and we can't catch c++ exception. Obvious workaround is to save to a variable (downloadStatus in my example) a state that knows when the map is being deleted and prevents deleting it again, but I still feel mapbox should throw Java exception so we can catch it.

@prompteus prompteus changed the title Android crash when canceling twice downloading offline map Android crash when canceling downloading offline map twice Aug 25, 2017
@Guardiola31337 Guardiola31337 added Android Mapbox Maps SDK for Android crash offline labels Aug 25, 2017
@tobrun
Copy link
Member

tobrun commented Aug 29, 2017

The underlying issue is being tracked in #8917. To close this issue we need to move the isDeleted outside the success block and reset it as part of onError in https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java#L364 for the upcoming patch release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android crash offline
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants