-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[android] returning null instead of the Source object in the MapboxMap#removeSource when it fails #13428
Conversation
d2c060e
to
881e405
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for picking this up @osana. Seeing that we return the source object to the user instead of true/false feels a bit strange to me. Take for example following codeblock:
geoJsonSource = mapboxMap.removeSource(geoJsonSource);
if(geoJsonSource == null){
// we couldn’t remove source
}
I think it makes more sense following the core setup to return true or false on the public api. If we would do this, we should also need to fix removeLayer
as well.
thoughts @mapbox/maps-android ?
I agree with @tobrun, |
86be772
to
b95dd52
Compare
@tobrun @LukasPaczos Do you think it makes sense to change |
Sure, shouldn't be an issue. |
618f45f
to
3281250
Compare
} | ||
|
||
/** | ||
* Remove with wrapper object id. Ownership is transferred back to the wrapper | ||
*/ | ||
void NativeMapView::removeLayer(JNIEnv&, jlong layerPtr) { | ||
jni::jboolean NativeMapView::removeLayer(JNIEnv&, jlong layerPtr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every other remove
method besides this one drops the reference to the layer, so the one kept in Java is probably going to become invalid. In order to make our intended logic possible, that a user fetches the layer with getLayer
(or just keeps the reference from the start) and can keep after it's removed from the map (successfully or not), we need to keep the reference valid.
@tobrun @LukasPaczos Capturing offline conversation of what needs to happen in this PR
We need the above two methods keep the reference alive ( transfer ownership from native to java peer) as it is done in Line 365 in 1ceea72
TODO: javadoc update & native_map_view.cpp change
Line 437 in 1ceea72
Line 448 in 1ceea72
in both cases the reference should be kept alive
|
9506127
to
bcc671c
Compare
jni::Local<jni::Object<Layer>> layerObj = | ||
LayerManagerAndroid::get()->createJavaLayerPeer(env, *map, std::move(coreLayer)); | ||
mbgl::android::Layer *layer = reinterpret_cast<mbgl::android::Layer *>(layerObj.get()); | ||
layer->setLayer(std::move(coreLayer)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tobrun could you ask someone with more knowledge of c++ how this should be done . Lines 846 -848 are not correct.
bcc671c
to
de18ed8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to add test covering a scenario when removal fails. Otherwise LGTM 👍
} | ||
return nativeRemoveLayerAt(index); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: new line
809d460
to
4630831
Compare
4630831
to
6c23514
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
closes #12526