From d1f444d63ed8048ec9b95e72ba4c72c3394e8379 Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 21 Feb 2017 15:33:59 +0200 Subject: [android] remove nonexistent layer or source handling --- platform/android/src/jni.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'platform/android/src/jni.cpp') diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 3f5f48561b..59602c3299 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -1188,11 +1188,8 @@ void nativeAddLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlon void nativeRemoveLayerById(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) { assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - try { - nativeMapView->getMap().removeLayer(std_string_from_jstring(env, id)); - } catch (const std::runtime_error& error) { - jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/layers/NoSuchLayerException"), error.what()); - } + + nativeMapView->getMap().removeLayer(std_string_from_jstring(env, id)); } /** @@ -1202,11 +1199,10 @@ void nativeRemoveLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, j assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); mbgl::android::Layer *layer = reinterpret_cast(layerPtr); - try { - std::unique_ptr coreLayer = nativeMapView->getMap().removeLayer(layer->get().getID()); + + std::unique_ptr coreLayer = nativeMapView->getMap().removeLayer(layer->get().getID()); + if (coreLayer) { layer->setLayer(std::move(coreLayer)); - } catch (const std::runtime_error& error) { - jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/layers/NoSuchLayerException"), error.what()); } } @@ -1246,22 +1242,17 @@ void nativeAddSource(JNIEnv *env, jni::jobject* obj, jni::jlong nativeMapViewPtr void nativeRemoveSourceById(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) { assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - try { - nativeMapView->getMap().removeSource(std_string_from_jstring(env, id)); - } catch (const std::runtime_error& error) { - jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/sources/NoSuchSourceException"), error.what()); - } + nativeMapView->getMap().removeSource(std_string_from_jstring(env, id)); } void nativeRemoveSource(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jlong sourcePtr) { assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); mbgl::android::Source *source = reinterpret_cast(sourcePtr); - try { - std::unique_ptr coreSource = nativeMapView->getMap().removeSource(source->get().getID()); + + std::unique_ptr coreSource = nativeMapView->getMap().removeSource(source->get().getID()); + if (coreSource) { source->setSource(std::move(coreSource)); - } catch (const std::runtime_error& error) { - jni::ThrowNew(*env, jni::FindClass(*env, "com/mapbox/mapboxsdk/style/sources/NoSuchSourceException"), error.what()); } } -- cgit v1.2.1