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 on iOS, when a Viro component being unmounted #324

Open
ariel-bentu opened this issue Feb 16, 2025 · 0 comments
Open

Crash on iOS, when a Viro component being unmounted #324

ariel-bentu opened this issue Feb 16, 2025 · 0 comments

Comments

@ariel-bentu
Copy link

Steps to reproduce:

  1. Start a fresh react-native app:
npx @react-native-community/cli init ViroBug --version 0.76
cd ViroBug
npm i @reactvision/react-viro
  1. Modify Podfile
  pod 'ViroReact', :path => '../node_modules/@reactvision/react-viro/ios/'
  pod 'ViroKit', :path => '../node_modules/@reactvision/react-viro/ios/dist/ViroRenderer/'
  1. Install pods:
cd iOS
pod install
  1. Replace the App.tsx with this code:
import { Viro3DSceneNavigator, ViroAmbientLight, ViroBox, ViroCamera, ViroMaterials, ViroNode, ViroQuad, ViroScene, ViroSpotLight } from "@reactvision/react-viro";
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
import { Button, SafeAreaView, View } from "react-native";


export default function App() {
    const sceneRef = useRef<any>(undefined);

    return (
        <SafeAreaView style={{ flex: 1 }} >
            <Button title="reload" onPress={() => sceneRef.current?.recreate()}></Button>

            <Viro3DSceneNavigator
                initialScene={{
                    scene: Scene1,

                    passProps: {
                        ref: sceneRef,
                    }
                }}
            />
        </SafeAreaView>
    );
}

export const Scene1 = forwardRef(({ }: any, ref: any) => {
    const [revision, setRevision] = useState<number>(0)

    useImperativeHandle(ref, () => ({
        recreate: () => {
            console.log("recreating scene")
            setRevision(prev => prev + 1)
        },
    }));

    return (
        <ViroScene key={revision}>
            {/* <ViroCamera active position={[0, 5, 2]} rotation={[-60, 0, 0]} /> */}
            <ViroAmbientLight color="#FFFFFF" intensity={500} />
            <ViroBox></ViroBox>
        </ViroScene>
    )
});
  1. Run the app on your device, and after it loads press the "reload" button

Result

app crashes with "EXC_BAD_ACCESS" at [_contentView removeFromSuperview];

// File: RCTViewComponentView.mm
...
- (void)setContentView:(UIView *)contentView
{
  if (_contentView) {
    [_contentView removeFromSuperview]; // here
  }
...

Notes:

  • this also happens for inner Viro objects such as Viro3DObject.
  • it happens more on real device, but often also on SImulator/ Mac (designed for iPad)
  • It happens on version react-native 0.76, but I tried also 0.77 and 0.77.1 and still the same
  • I tried on 0.78 rc 5 - and encountered a blocker (which I did not investigate) about old react element being rendered... so gave up on that release check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant