[might be a bug] Camera.getAvailablePictureSizesAsync throw error with proper args.

I get ratio using this.Camera!.getSupportedRatiosAsync() then pass it to this.Camera!.getAvailablePictureSizesAsync(ratio).
This should not throw error, but I got an error every time I tried.

My code are below

class Screen extends React.Component {
  render() {
    return (
        ref={this.setRef as any}
        // zoom={zoom}

  updateStateForCameraProps = () => {
    if (Platform.OS === 'android') {
      InteractionManager.runAfterInteractions(async () => {
        const ratios = await this.Camera!.getSupportedRatiosAsync()
        const [ratio, dimensions] = pickRatio_calcDimensions(ratios)
        console.log({ ratios, ratio })
        const sizes = await this.Camera!.getAvailablePictureSizesAsync(ratio)
        this.setState({ pictureSize: sizes[0], cameraStyle: dimensions })
        console.log({ sizes })

function pickRatio_calcDimensions(ratios: string[]): [string, ViewStyle] {
  const ratio = ratios[getIndexOfMinRatio(ratios)]
  const [height, width] = getDimensionsFromRatio(ratio)
  const dimensions: ViewStyle = { width: windowWidth, height: (windowWidth * height) / width }
  return [ratio, dimensions]

and console log shows

Object {
  "ratio": "11:9",
  "ratios": Array [

[Unhandled promise rejection: Error: getAvailablePictureSizes -- unexpected error -- Attempt to invoke interface method 'int java.util.SortedSet.size()' on a null object reference]
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:146:41 in createErrorFromErrorData
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:95:55 in <unknown>
- ... 5 more stack frames from framework internals

It works if ratio = "4:3", but not ratio = "11:9".

I didn’t try others ( “5:3”, “16:9”, “30:17” ).

Is there any solution for this?

Hey @plusuno,

Can you let me know what SDK version this is occurring on and could you create a Snack that reproduces this issues so we can test it on our end?



Hi @adamjnav,
Thank you for your reply.

I’m using SDK 32 and the part of the dependencies are below

  "dependencies": {
    "expo": "32.0.6",
    "expo-localization": "2.0.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.1.tar.gz"

I created snack.
But I’m not sure this link is public or not, and I didn’t delete all unnecessary code >_<.
I hope these are enough!

logs are below.
“FTJ161B” is my Android phone

FTJ161B: camera is ready 2


Should show “sizes” in log, but the app crashed?
No errors appears on Snack but app stop…

Preview app is just white on Snack, and my Android device too.

Thanks :smiley:

Hello @adamjnav

Since there is no similar issue even a lot of people using EXPO, I guess this bug is caused by my Android device.

Now I’m setting “4:3” if exist, to avoid error, and If I got some error related to this in production, I can avoid by try catch loop I think.

Is there anything or “just because of by device”?

Thank you for your help :smiley:

@adamjnav hello…

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.