nitaliano / react-native-mapbox-gl

A Mapbox GL react native module for creating custom maps
Other
2.16k stars 697 forks source link

[6.1.3][iOS] iconAnchor crush #1498

Closed fantasywind closed 5 years ago

fantasywind commented 5 years ago

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" />
barsumek commented 5 years ago

@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.

kristfal commented 5 years ago

This is now fixed in master.

stephenheron commented 5 years ago

@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.

kristfal commented 5 years ago

@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 :)

stephenheron commented 5 years ago

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

KasparasGud commented 5 years ago

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 !

huszzsolt commented 5 years ago

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

romixch commented 5 years ago

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!?

martinezguillaume commented 5 years ago

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

huszzsolt commented 5 years ago

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.

dorthwein commented 5 years ago

getting this in RN 59

mattijsf commented 5 years ago

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.

mattijsf commented 5 years ago

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

huszzsolt commented 5 years ago

@mattijsf Thanks, #1593 fixed the crash.

L-Yeiser commented 5 years ago

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

mattijsf commented 5 years ago

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

L-Yeiser commented 5 years ago

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

mattijsf commented 5 years ago

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?

L-Yeiser commented 5 years ago

@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.