Skip to content

[iOS] - ARSession needs to be deallocated before being paused. #333

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

Open
oliedis opened this issue Apr 15, 2025 · 5 comments
Open

[iOS] - ARSession needs to be deallocated before being paused. #333

oliedis opened this issue Apr 15, 2025 · 5 comments
Assignees
Labels
to be released It's fixed/done and coming in a next update

Comments

@oliedis
Copy link
Contributor

oliedis commented Apr 15, 2025

ViroReact Version: @reactvision/react-viro version ^2.43.0

React Native version: 0.77.1

Expo: Not being used

Getting the following error:

ARSession <0x114d6ad00>: ARSession is being deallocated without being paused. Please pause running sessions explicitly.

app index.tsx

import React, {useCallback, useEffect, useRef, useState} from 'react';
import {
  ViroARScene,
  ViroARSceneNavigator,
  Viro3DObject,
  ViroAmbientLight,
  ViroARPlaneSelector,
  ViroMaterials,
  ViroBox,
  ViroText,
  ViroSpotLight,
  ViroNode,
} from '@reactvision/react-viro';
import {
  AppState,
  Image,
  Platform,
  StyleSheet,
  TouchableOpacity,
  View,
} from 'react-native';
import {useNavigation} from '@react-navigation/native';
import {crossing, iosmodel} from '~/assets';
import {RF} from '~/shared/services/utils/responsive';
import {useDispatch} from 'react-redux';
import {setArView} from '~/shared/redux';
ViroMaterials.createMaterials({
  debugRed: {
    diffuseColor: '#ff0000',
  },
});

const HelloWorldSceneAR = () => {
  const modelSource =
    Platform.OS === 'android'
      ? {uri: 'file:///android_asset/sofa.glb'}
      : iosmodel;
  const [rotation, setRotation] = useState<[number, number, number]>([0, 0, 0]);

  const handleRotate = (
    rotateState: number,
    rotationFactor: number,
    source: any,
  ) => {
    if (rotateState === 3) {
      // Finished rotating
      setRotation(prev => [prev[0], prev[1] + rotationFactor, prev[2]]);
    }
  };
  return (
    // <></>
    <ViroARScene>
      <ViroAmbientLight color={'#aaaaaa'} />
      <ViroSpotLight
        innerAngle={5}
        outerAngle={90}
        direction={[0, -1, -0.2]}
        position={[0, 3, 1]}
        color="#ffffff"
        castsShadow={true}
      />
      <ViroARPlaneSelector maxPlanes={1}>
        <ViroNode rotation={rotation} onRotate={handleRotate}>
          <Viro3DObject
            source={modelSource}
            position={[0, 0.1, 0]}
            scale={[2, 2, 2]}
            type="GLB"
          />
        </ViroNode>
      </ViroARPlaneSelector>
    </ViroARScene>
  );
};

export default function ArComponent() {
  const navigation = useNavigation();
  const dispatch = useDispatch();
  const [showAr, setShowAr] = useState(true);
  const arNavigatorRef = useRef<any>(null);
  const handleClose = () => {
    // Set a delay before executing the actions
    setShowAr(false);
    console.log(arNavigatorRef.current, '...cirrrent');
    setTimeout(() => {
      // console.log(arNavigatorRef, 'arNavigatorRef');
      dispatch(setArView(false));
      navigation.goBack();
    }, 500); // 500 milliseconds delay (you can adjust this time)
  };

  return (
    <View style={{flex: 1}}>
      {showAr && (
        <ViroARSceneNavigator
          ref={arNavigatorRef}
          autofocus={true}
          initialScene={{scene: HelloWorldSceneAR}}
          style={styles.f1}
        />
      )}

      <TouchableOpacity style={styles.closeButton} onPress={handleClose}>
        <Image
          source={crossing}
          style={{width: RF(24), height: RF(24), resizeMode: 'contain'}}
        />
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  f1: {flex: 1},
  closeButton: {
    position: 'absolute',
    top: 40,
    right: 20,
    zIndex: 100,
    backgroundColor: '#fff',
    borderRadius: 4,
    padding: 5,
  },
  helloWorldTextStyle: {
    fontFamily: 'Arial',
    fontSize: 30,
    color: '#ffffff',
    textAlignVertical: 'center',
    textAlign: 'center',
  },
});
@doranteseduardo
Copy link
Member

I've been trying to reproduce this issue without success, it would be helpful if I can get a reproducible project.

@jerryCh254
Copy link

Sure! If you can please share your email, I’ll add you to the repository. You can then pull the branch directly and check the issue there.
Let me know once done.

@jerryCh254
Copy link

jerryCh254 commented Apr 16, 2025

When I close the AR, I mean when I cross the AR.
Image

@doranteseduardo
Copy link
Member

Sure! If you can please share your email, I’ll add you to the repository. You can then pull the branch directly and check the issue there.
Let me know once done.

[email protected]

@jerryCh254
Copy link

I’ve added you as a collaborator to the GitHub repository.

Please check your email or GitHub notifications and confirm access. Let me know if you face any issues.

Thanks!

@doranteseduardo doranteseduardo added the to be released It's fixed/done and coming in a next update label Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to be released It's fixed/done and coming in a next update
Projects
None yet
Development

No branches or pull requests

3 participants