@@ -1018,6 +1018,7 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
10181018 this . syncBboxVisibility ( ) ;
10191019
10201020 if ( ! hasInputData ( inputData ) ) {
1021+ this . resetEphemeralState ( ) ;
10211022 return ;
10221023 }
10231024
@@ -1031,6 +1032,7 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
10311032 this . subscriptions . add (
10321033 this . $invert . listen ( ( ) => {
10331034 if ( ! hasInputData ( this . $inputData . get ( ) ) ) {
1035+ this . resetEphemeralState ( ) ;
10341036 return ;
10351037 }
10361038
@@ -1044,6 +1046,7 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
10441046 this . subscriptions . add (
10451047 this . $model . listen ( ( ) => {
10461048 if ( ! hasInputData ( this . $inputData . get ( ) ) ) {
1049+ this . resetEphemeralState ( ) ;
10471050 return ;
10481051 }
10491052
@@ -1057,6 +1060,7 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
10571060 this . subscriptions . add (
10581061 this . manager . stateApi . createStoreSubscription ( selectAutoProcess , ( autoProcess ) => {
10591062 if ( ! hasInputData ( this . $inputData . get ( ) ) ) {
1063+ this . resetEphemeralState ( ) ;
10601064 return ;
10611065 }
10621066 if ( autoProcess ) {
@@ -1428,7 +1432,10 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
14281432 }
14291433
14301434 // Empty internal module state - default to visual mode
1431- this . $inputData . set ( { type : 'visual' , points : [ ] , bbox : null } ) ;
1435+ // Careful! If we set input data here and it was already empty, it will trigger an infinite loop of resets. So only set if needed.
1436+ if ( hasInputData ( this . $inputData . get ( ) ) ) {
1437+ this . $inputData . set ( { type : 'visual' , points : [ ] , bbox : null } ) ;
1438+ }
14321439 this . $imageState . set ( null ) ;
14331440 this . $pointType . set ( 1 ) ;
14341441 this . $invert . set ( false ) ;
0 commit comments