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

Commit

Permalink
[android] Fix the crash when CameraPosition padding is set. (#15699)
Browse files Browse the repository at this point in the history
* [android] Add test branch, navigate to Map Snapshotter activity to reproduce the bug.

* [android] Fix the crash when camera position padding is set.
  • Loading branch information
pengdev authored and Langston Smith committed Sep 25, 2019
1 parent 6920111 commit b1d9774
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private void startSnapShot(final int row, final int column) {
.bearing(randomInRange(0, 360))
.tilt(randomInRange(0, 60))
.zoom(randomInRange(0, 20))
.padding(1, 1, 1, 1)
.build()
);
}
Expand Down
21 changes: 11 additions & 10 deletions platform/android/src/map/camera_position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b1d9774

Please sign in to comment.