[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.
This commit is contained in:
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user