@@ -510,6 +510,10 @@ export function createXRStore<T extends XRElementImplementations>(options?: XRSt
510
510
const frameRequests : Array < ( frame : XRFrame ) => void > = [ ]
511
511
let xrManager : WebXRManager | undefined
512
512
513
+ const onSessionStart = ( ) => {
514
+ store . setState ( bindToSession ( xrManager ! . getSession ( ) ! ) )
515
+ }
516
+
513
517
return Object . assign ( store , {
514
518
addLayerEntry ( layerEntry : XRLayerEntry ) : void {
515
519
if ( store . getState ( ) . session == null ) {
@@ -530,7 +534,9 @@ export function createXRStore<T extends XRElementImplementations>(options?: XRSt
530
534
if ( xrManager === newXrManager ) {
531
535
return
532
536
}
537
+ xrManager ?. removeEventListener ( 'sessionstart' , onSessionStart )
533
538
xrManager = newXrManager
539
+ xrManager . addEventListener ( 'sessionstart' , onSessionStart )
534
540
const { foveation, bounded } = options ?? { }
535
541
xrManager . setReferenceSpaceType ( bounded ? 'bounded-floor' : 'local-floor' )
536
542
if ( foveation != null ) {
@@ -606,6 +612,7 @@ export function createXRStore<T extends XRElementImplementations>(options?: XRSt
606
612
store . setState ( { screenInput : implementation } )
607
613
} ,
608
614
destroy ( ) {
615
+ xrManager ?. removeEventListener ( 'sessionstart' , onSessionStart )
609
616
cleanupEmulate ?.( )
610
617
cleanupDomOverlayRoot ?.( )
611
618
cleanupSessionGrantedListener ?.( )
@@ -644,10 +651,6 @@ export function createXRStore<T extends XRElementImplementations>(options?: XRSt
644
651
if ( xrManager != null ) {
645
652
updateSession ( store , frame , xrManager )
646
653
}
647
- if ( state . session == null && referenceSpace != null && frame . session != null ) {
648
- update ??= { }
649
- Object . assign ( update , bindToSession ( frame . session ) )
650
- }
651
654
if ( state . body != frame . body ) {
652
655
update ??= { }
653
656
update . body = frame . body
0 commit comments