-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] Crashes caused by dangling rawSource pointer after new style is parsed. #15333
Comments
@julianrex I think this is an API usability issue, not a bug. There are many platform and library APIs that work in the same way. Objects become invalid once the owner of objects is invalidated.
Style change invalidates all source / layer objects. If needed, platform can detach required objects before style is changed and re-attach if needed after new style finished loading, or on demand, when MGLSource / Layer is accessed. Another option would be to change core API, so that we operate with shared pointers to Source / Layer (maybe even Style). @pozdnyakov wdyt? |
@alexshalamov I agree that this sound more like API usability issue. It would be better if we do not expose source and layer objects as their lifecycle is not quite clear, instead we could export generic key-value API for setting a style. |
This may be an internal API issue, i.e. between the platform and core - but we should assume that developers could hold on to the iOS objects for a long time (even if they become "invalid" for some reason). |
@julianrex I agree that API provided by core is not the most elegant or well documented, however, ownership is more or less clearly defined.
Platform can track MGL* objects that were given out to the client and detach core objects (removeSource / Layer) before style is changed. |
It would be useful for core to emit lifecycle events to the platform for the top level style objects. The |
The plan for fixing the issue is that |
Does this need to be handled on the @mapbox/maps-android side as well? |
A similar issue to this was addressed for Android in #9983, specifically these changes: Maybe @LukasPaczos is aware of continued issues with stale pointers in the Android SDK. |
The weak pointer setup as outlined by @pozdnyakov in #15333 (comment) would be the ideal solution for Android as well. We currently have some workaround in place that flags a source/layer being "detached", being able to check the pointer if it's still valid would be ideal solution. |
If a developer retains a
MGLSource
, then sets a new style URL (loading a new style), then thatMGLSource
will end up with a danglingrawSource
pointer.In
Style::Impl::parse
we havesources.clear();
without a mechanism that updates the platform object. The fact this doesn't crash immediately when accessing the rawSource pointer is just pure luck.Interestingly @asheemmamoowala and I worked on a similar issue with
CustomLayer
/RenderCustomLayer
. I think a similar mechanism may be needed here; it's a generic enough problem.Related: #6180
/cc @samfader @tmpsantos @frederoni
The text was updated successfully, but these errors were encountered: