expo: [expo-gl][SDK 44][Android] GLView causes crash on startup

Summary

When trying to run the GLView demo app with Expo SDK 44 in managed workflow (Expo GO) on Android, the app crashes immediately. (On SDK 43, it works fine.)

Phones:

  • Samsung Galaxy A32 (SM-A326B)
  • Google Pixel 4a

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

44

Environment

Expo CLI 5.0.3 environment info: System: OS: macOS 10.15.7 Shell: 5.0.16 - /usr/local/bin/bash Binaries: Node: 16.13.1 - /usr/local/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 8.3.0 - /usr/local/bin/npm Watchman: 2022.01.03.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7935034 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: expo: ~44.0.0 => 44.0.4 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 npmGlobalPackages: eas-cli: 0.43.0 expo-cli: 5.0.3 Expo Workflow: managed

Reproducible demo

expo init [choose blank (Typescript)]
expo install expo-gl

Replace App.tsx with demo from GLView docs (see below).

expo start

App.tsx:

import React from 'react';
import { View } from 'react-native';
import { GLView } from 'expo-gl';

export default function App() {
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <GLView style={{ width: 300, height: 300 }} onContextCreate={onContextCreate} />
    </View>
  );
}

function onContextCreate(gl) {
  gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  gl.clearColor(0, 1, 1, 1);

  // Create vertex shader (shape & position)
  const vert = gl.createShader(gl.VERTEX_SHADER);
  gl.shaderSource(
    vert,
    `
    void main(void) {
      gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
      gl_PointSize = 150.0;
    }
  `
  );
  gl.compileShader(vert);

  // Create fragment shader (color)
  const frag = gl.createShader(gl.FRAGMENT_SHADER);
  gl.shaderSource(
    frag,
    `
    void main(void) {
      gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
    }
  `
  );
  gl.compileShader(frag);

  // Link together into a program
  const program = gl.createProgram();
  gl.attachShader(program, vert);
  gl.attachShader(program, frag);
  gl.linkProgram(program);
  gl.useProgram(program);

  gl.clear(gl.COLOR_BUFFER_BIT);
  gl.drawArrays(gl.POINTS, 0, 1);

  gl.flush();
  gl.endFrameEXP();
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 24 (4 by maintainers)

Most upvoted comments

A little bit more information:

  • I was able to reproduce it on a Google Pixel 4a as well
  • I can also reproduce it with a completely empty onContextCreate method (function onContextCreate(gl) {})
  • When I set the width and height to 0 (or otherwise give no space to the component), the crash does not occur. However, when I set it back and save (to make Expo GO update the app), the app crashes immediately.

Tested this on iOS and Android devices, same setup. Expo SDK 44, create a new project, expo install expo-gl and paste the minimal example app. Running via Expo Go.

  • iOS simulator, iOS 15.0: works
  • iOS device, iPad 8th gen, iOS 15.2: works
  • Android emulator, Pixel 4 model, Android 10/Q = API 29: works
  • Android emulator, Pixel 4 model, Android 11/R = API 30: works
  • Android emulator, Pixel 4 model, Android 12/S = API 31: works
  • Android device, Nokia 3.4, Android 10/Q = API 29: works
  • Android device, Nokia 3.4, Android 11/R = API 30: chrashes
  • Android device, Samsung Galaxy S20 FE 5G, Android 12/S = API 31: chrashes

From my limited testing it seems like the issue occurs only on Android devices with API 30 or higher.

Looks like this problem is back again with SDK 47. Tested in the Expo Go App, with a Google Pixel 6 on Android 13.

It was working fine with SDK 45 and SDK 46. I just upgraded to SDK 47 and it’s crashing again as soon as I set a size to the GLView, no error message in the console. I tried upgrading expo-three to “^6.2.0” and three to “^0.146.0”, but still crashing. I also tried using the hermes js engine, no luck.

You can test the doc example Basic GL Usage https://docs.expo.dev/versions/latest/sdk/gl-view/#usage At line 8, if you remove the style tag of the GLView component, or set the width and height to 0, it is not crashing (but not visible as well) If you set a width and height, it is crashing (same with flex).

@wkozyra95 Thanks! I can verify that upgrading to Expo SDK 45 solved the issue. Tested on Samsung Galaxy A32 (SM-A326B).

Any update with this issue? This is driving our dev team nuts.

There might be few reasons for those issues

  • if you are using expo-pixi or expo-three update to the latest version or add delete global.WebGLRenderingContext after import
  • if you are using react-native@0.65 or newer it might not work and we can’t do much about it(but you can upgrade to sdk45 with react-native 0.68)
  • on some devices integration between reanimated and expo-gl might cause crash on start, to disable integration you can add delete global._WORKLET_RUNTIME (or upgrade to sdk45)