React-native-mapbox-gl: [6.1.3][iOS] iconAnchor crush

Created on 1 Feb 2019  Â·  19Comments  Â·  Source: nitaliano/react-native-mapbox-gl

Hi, I tried to set the SymbolLayer style __iconAnchor__ to 'buttom' or MapboxGL.IconAnchor.Bottom like #1061. The iOS app will crash on real device whatever debug build or release build (but simulator work normally).

But if iconAnchor is 'center' or MapboxGL.IconAnchor.Center work good!

__Error Log__

Assertion failed: (it != std::end(MGLIconAnchor_names)), function toString, file /Users/distiller/project/platform/darwin/src/MGLSymbolStyleLayer.mm, line 26.

__style__

const mbStyles = MapboxGL.StyleSheet.create({
  icon: {
    iconImage: '{icon}',
    iconAllowOverlap: true,
    iconAnchor: MapboxGL.IconAnchor.Bottom,
  },
});

// JSX
<MapboxGL.SymbolLayer
  filter={['==', '$type', 'Point']}
  style={mbStyles.icon}
  id="point" />

Most helpful comment

@fantasywind I also ran into this and it looks like there's a problem with MapboxGL.StyleSheet.create JS mapping to native iOS values on newer versions of React Native – it worked fine on 0.56 but crashes on 0.58.3.

It fails when it tries to match the passed integer to an enum here:
https://github.com/mapbox/mapbox-gl-native/blob/f3341dd589c6330c0cfd6e8e381398d08493b48a/include/mbgl/util/enum.hpp

I needed a fix ASAP, so I've just forced the needed value natively.

- (void)setIconAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue
{
    NSArray<NSString*> *allowedFunctionTypes = @[@"camera", @"source", @"composite"];
    if ([styleValue isFunction] && ![styleValue isFunctionTypeSupported:allowedFunctionTypes]) {
        // TODO throw execpetion
        return;
    }
    // ignore the passed value and just force the one you need
    MGLStyleValue *forceBottomAnchor = [MGLStyleValue valueWithRawValue:@(MGLIconAnchorBottom)];
    layer.iconAnchor = forceBottomAnchor;
}

Ofc it's not a generic nor correct solution, especially because other styles which use enums are failing as well, but it suited my needs so maybe it will help you too. 😄

I recommend using patch-package for such hacky fixes, but of course you can do a fork as well.

All 19 comments

@fantasywind I also ran into this and it looks like there's a problem with MapboxGL.StyleSheet.create JS mapping to native iOS values on newer versions of React Native – it worked fine on 0.56 but crashes on 0.58.3.

It fails when it tries to match the passed integer to an enum here:
https://github.com/mapbox/mapbox-gl-native/blob/f3341dd589c6330c0cfd6e8e381398d08493b48a/include/mbgl/util/enum.hpp

I needed a fix ASAP, so I've just forced the needed value natively.

- (void)setIconAnchor:(MGLSymbolStyleLayer *)layer withReactStyleValue:(RCTMGLStyleValue *)styleValue
{
    NSArray<NSString*> *allowedFunctionTypes = @[@"camera", @"source", @"composite"];
    if ([styleValue isFunction] && ![styleValue isFunctionTypeSupported:allowedFunctionTypes]) {
        // TODO throw execpetion
        return;
    }
    // ignore the passed value and just force the one you need
    MGLStyleValue *forceBottomAnchor = [MGLStyleValue valueWithRawValue:@(MGLIconAnchorBottom)];
    layer.iconAnchor = forceBottomAnchor;
}

Ofc it's not a generic nor correct solution, especially because other styles which use enums are failing as well, but it suited my needs so maybe it will help you too. 😄

I recommend using patch-package for such hacky fixes, but of course you can do a fork as well.

This is now fixed in master.

@kristfal Cheers, we had the same issue and it appears to be fixed on master. Could you point me in the direction of what the fix was? I had a look but I can't see where the fix was made. Just interested for my own understanding of how react-native-mapbox-gl works under the hood.

@stephenheron I do believe it was caused by some missing enums in the native iOS side, but tbh, I don't remember the exact fix and I changed too much in one PR to easily find back to the fix.

Next time I'll do smaller PRs :)

@kristfal No worries! Cheers for fixing the issue in the first place!

Still not working for me on master. Setting the icon anchor to bottom leads to the same crash as @fantasywind described.

@barsumek workaround works for now! Thanks !

I have the same problem. A SIGABRT is generated in CTMGLStyle.m by
(void)setLineJoin:(MGLLineStyleLayer *)layer:
layer.lineJoin = styleValue.mglStyleValue;

Issues go away if i remove from _icon_ remove the _iconAnchor: 'bottom'_
respectively from _line_ the _lineJoin: 'round'_
in MapboxGL.StyleSheet.create()

Using master
and just move to RN 0.59.2 and XCode 10.2. With previous RN 0.57.8 was all fine.
Tried on simulator only

I had the same issue. Needed to use the hacky patch fix. Would be nice if there was a new release soon. The last one is 8(!) months ago!?

Same issue as @huszzsolt on master for me, only iOS

I have spent some time trying to debug this, but no success.

I've just noticed that on iPhone6s simulator does not crash, while on iPhone X it crashes.

getting this in RN 59

I'm also getting this. It's not happening all the time. For the past few days I didn't have it, then I switched from an iPhone 5s simulator to iPhone X simulator and I got the error. After some reloads / rebuilds it was gone, I switched to an iPhone SE simulator and the error popped up again... I'm totally clueless for now.

In my previous comment I mentioned that the error was "magically" gone after some time, I think that was due to testing code was being commented out without being aware of it. At a certain point I could reproduce this problem consistently and created a workaround in https://github.com/nitaliano/react-native-mapbox-gl/pull/1593

@mattijsf Thanks, #1593 fixed the crash.

I have a forked branch pointing to master and I am still running into issues setting the iconAnchor property.

@L-Yeiser Have you also rebuild the app/library in Xcode?

I did - I also tested a production build assembled via fastlane / testflight.

Strange. I've tested it myself and with multiple colleagues who experienced that same error. It was fixed after the merged changes.

Just as another check, can you verify that the code [NSValue value:&uintValue withObjCType:@encode(NSUInteger)]
is present in RCTMGLStyleValue.m and that it is hit when a style with iconAnchor is assigned?

@mattijsf I just tried reproing it in dev and it is working. I will push out another production build and test again. We had some CI issues this week which could have caused a false negative.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VentsislavDinev picture VentsislavDinev  Â·  3Comments

Maxence-Machu picture Maxence-Machu  Â·  3Comments

smoll picture smoll  Â·  4Comments

Gp2mv3 picture Gp2mv3  Â·  3Comments

digitaldavenyc picture digitaldavenyc  Â·  4Comments