diff options
author | Peng Liu <peng.liu@mapbox.com> | 2019-09-23 19:11:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-23 19:11:00 +0300 |
commit | 426da3a6af88f32a6d68d9c1990ac06a4e540f50 (patch) | |
tree | ef8c6764ed1dfd701dea182d622e4486dfbbb844 /platform | |
parent | 29dd824e3b09adc1f1318f23bee0053a26dd4927 (diff) | |
download | qtlocation-mapboxgl-426da3a6af88f32a6d68d9c1990ac06a4e540f50.tar.gz |
[android] Fix the crash when CameraPosition padding is set. (#15699)
* [android] Add test branch, navigate to Map Snapshotter activity to reproduce the bug.
* [android] Fix the crash when camera position padding is set.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java | 1 | ||||
-rw-r--r-- | platform/android/src/map/camera_position.cpp | 21 |
2 files changed, 12 insertions, 10 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java index 59c708266e..ab7ffed83e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java @@ -89,6 +89,7 @@ public class MapSnapshotterActivity extends AppCompatActivity { .bearing(randomInRange(0, 360)) .tilt(randomInRange(0, 60)) .zoom(randomInRange(0, 20)) + .padding(1, 1, 1, 1) .build() ); } diff --git a/platform/android/src/map/camera_position.cpp b/platform/android/src/map/camera_position.cpp index cbf5f2e408..4266b64fdf 100644 --- a/platform/android/src/map/camera_position.cpp +++ b/platform/android/src/map/camera_position.cpp @@ -44,19 +44,20 @@ mbgl::CameraOptions CameraPosition::getCameraOptions(jni::JNIEnv& env, const jni static auto tilt = javaClass.GetField<jni::jdouble>(env, "tilt"); static auto zoom = javaClass.GetField<jni::jdouble>(env, "zoom"); static auto paddingField = javaClass.GetField<jni::Array<jni::jdouble>>(env, "padding"); - static auto padding = position.Get(env, paddingField); + auto padding = position.Get(env, paddingField); auto center = LatLng::getLatLng(env, position.Get(env, target)); - return mbgl::CameraOptions { - center, - padding ? EdgeInsets {padding.Get(env, 1) * pixelRatio, padding.Get(env, 0) * pixelRatio, - padding.Get(env, 3) * pixelRatio, padding.Get(env, 2) * pixelRatio} : (EdgeInsets) {}, - {}, - position.Get(env, zoom), - position.Get(env, bearing), - position.Get(env, tilt) - }; + return mbgl::CameraOptions{center, + padding && padding.Length(env) == 4 ? EdgeInsets{padding.Get(env, 1) * pixelRatio, + padding.Get(env, 0) * pixelRatio, + padding.Get(env, 3) * pixelRatio, + padding.Get(env, 2) * pixelRatio} + : (EdgeInsets){}, + {}, + position.Get(env, zoom), + position.Get(env, bearing), + position.Get(env, tilt)}; } void CameraPosition::registerNative(jni::JNIEnv &env) { |