Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when switching away from app on iOS #3957

Closed
fivecar opened this issue Sep 16, 2021 · 5 comments
Closed

Crash when switching away from app on iOS #3957

fivecar opened this issue Sep 16, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@fivecar
Copy link
Contributor

fivecar commented Sep 16, 2021

Bug report

Summary

<MapView> crashes on iOS if you switch away from the app to another app, with EXC_BAD_ACCESS (code=EXC_I386_GPFLT). This happens only if you use maptype="standard" with the default provider (Apple Maps), and is consistently reproducible if you use flex:1 (though it also reproduces intermittently if you specify exact dimensions [width/height]).

Environment info

Using standard out-of-the-box Apple Maps.

react-native info output:

System:
    OS: macOS 11.5.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 19.07 MB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.22.5 - ~/.nvm/versions/node/v12.22.5/bin/node
    Yarn: 1.22.11 - /usr/local/bin/yarn
    npm: 7.23.0 - ~/.nvm/versions/node/v12.22.5/bin/npm
    Watchman: 2021.09.06.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.6953283
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.3 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.65.1 => 0.65.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
  "dependencies": {
    "react": "17.0.2",
    "react-native": "0.65.1",
    "react-native-maps": "^0.29.3"
  },

Steps to reproduce

  1. npx react-native init MyApp --template react-native-template-typescript
  2. yarn add react-native-maps
  3. yarn && cd ios && pod install
  4. Set up your App in App.tsx to use MapView (shown below). To get a consistent repro, start with flex:1.
  5. Open MyApp/ios/MyApp.xcworkspace in XCode.
  6. Build and run in simulator (e.g. iPhone 8 Plus). Though it reproduces on real devices as well.
  7. Once app is launched and in foreground, switch apps. Either double-tap the home button and choose a different app, or double-tap home and tap anywhere outside the app (to get to your iPhone's main screen).
const App = () => {
  return <MapView style={{flex: 1}} />;
};

Describe what you expected to happen:

  1. Successful switching out of MyApp with no issues

Describe what you actually happens:

  1. EXC_BAD_ACCESS (code=EXC_I386_GPFLT) crash, shown in XCode debugger.

Reproducible sample code

https://gist.github.com/fivecar/5aaca5b99d37a011a5793be21b502c7d. The cleanest way to set this up is to follow the repro instructions above.

NOTE: It took me some time to figure this out, but there are three important caveats:

  1. It reproduces consistently with flex:1 but inconsistently with specifying a defined width/height (e.g. width: 400, height: 400). So if you insist on setting a width/height, you'll need to fiddle a few times, recompiling things, re-running it, to get the repro. I find that running once with flex:1 and then setting explicit width/height is pretty consistent. But 100% reliable is simply sticking with flex:1. (App crashing when being put into background with MapView component mounted #3650 claims that width/height fixes it, but I've done some pretty thorough testing that suggests it's simply less reliable to repro with width/height).
  2. This does not reproduce, ever, if you set mapType to anything but standard. If you set it to satellite or hybrid, etc, it won't reproduce. So either set it to standard, or don't set mapType at all.
  3. This goes away if you use provider={PROVIDER_GOOGLE}

It took a long time, some git bisect, and a bunch of style fiddling to figure out the minimum repro on this. But I'm surprised others haven't reported this, given how reliable it reproduces (and how consequential the aftermath). I'm happy to help fix this if someone points me the right direction, but I've never looked into the codebase and would largely be stabbing in the dark.

@monholm
Copy link
Collaborator

monholm commented Sep 21, 2021

I'm not a maintainer/contributor of this package (yet... ;)), but my company do however use it in production, so I was compelled to look into this.

First of all, could you please confirm that you are only experiencing this when running through Xcode? Are you able to relaunch/refocus your app after opening the multitasking window running through react-native run-ios?

I suspect that this is the reason why this issue isn't reported more widely.

If you are able to confirm the above, please try to edit your scheme to disable Metal Api Validation.

Click your scheme name (likely your project name) to the left of your target device, press Edit Scheme... then go to the Diagnostics tab and disable the API Validation option under Metal.

Re-run your app through Xcode. This should "fix" the crash. Do you observe this as well?

If so, your crash is caused by Xcode running a Metal debugger when running through Xcode. I don't think this is caused by react-native-maps as the crash can be reproduced by running a barebone Xcode iOS project with nothing but a MKMapView in the main storyboard. As this doens't affect production builds, I don't have the time to look into why this is happening, but Google seems to suggest that this is a widespread error.

The crash shouldn't affect your production builds what so ever. Feel free to get back to me if the above doesn't match your experience.

@fivecar
Copy link
Contributor Author

fivecar commented Sep 21, 2021

@Simon-TechForm : Thanks for your really helpful and detailed answer. You're absolutely right — running outside the debugger, or turning off Metal API Validation, both make the issue go away. I've just verified both things as suggested.

Closing the issue!

@fivecar
Copy link
Contributor Author

fivecar commented Sep 21, 2021

Created #3961 to add this to the Troubleshooting section of the readme.

christopherdro pushed a commit that referenced this issue Sep 22, 2021
* Update readme to address #3957

* Update readme link correctly

* Fix spacing to be minimal delta from existing README

Co-authored-by: Philip Su <philip@auderenow.org>
borjomemost pushed a commit to borjomemost/react-native-maps that referenced this issue May 6, 2022
…ing tip (react-native-maps#3961)

* Update readme to address react-native-maps#3957

* Update readme link correctly

* Fix spacing to be minimal delta from existing README

Co-authored-by: Philip Su <philip@auderenow.org>
@Mansi-Bigstep
Copy link

Mansi-Bigstep commented Jul 21, 2022

Hello , i got the same issue, however on unchecking api validation the error doesn't go while running in debug mode. For production mode , i archieved it with release mode still it is crashing. Please let me know other steps.

@Mansi-Bigstep
Copy link

I'm not a maintainer/contributor of this package (yet... ;)), but my company do however use it in production, so I was compelled to look into this.

First of all, could you please confirm that you are only experiencing this when running through Xcode? Are you able to relaunch/refocus your app after opening the multitasking window running through react-native run-ios?

I suspect that this is the reason why this issue isn't reported more widely.

If you are able to confirm the above, please try to edit your scheme to disable Metal Api Validation.

Click your scheme name (likely your project name) to the left of your target device, press Edit Scheme... then go to the Diagnostics tab and disable the API Validation option under Metal.

Re-run your app through Xcode. This should "fix" the crash. Do you observe this as well?

If so, your crash is caused by Xcode running a Metal debugger when running through Xcode. I don't think this is caused by react-native-maps as the crash can be reproduced by running a barebone Xcode iOS project with nothing but a MKMapView in the main storyboard. As this doens't affect production builds, I don't have the time to look into why this is happening, but Google seems to suggest that this is a widespread error.

Hello , i got the same issue, however on unchecking api validation the error doesn't go while running in debug mode. For production mode , i archieved it with release mode still it is crashing. Please let me know other steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants