@@ -1018,6 +1018,7 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
1018
1018
this . syncBboxVisibility ( ) ;
1019
1019
1020
1020
if ( ! hasInputData ( inputData ) ) {
1021
+ this . resetEphemeralState ( ) ;
1021
1022
return ;
1022
1023
}
1023
1024
@@ -1031,6 +1032,7 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
1031
1032
this . subscriptions . add (
1032
1033
this . $invert . listen ( ( ) => {
1033
1034
if ( ! hasInputData ( this . $inputData . get ( ) ) ) {
1035
+ this . resetEphemeralState ( ) ;
1034
1036
return ;
1035
1037
}
1036
1038
@@ -1044,6 +1046,7 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
1044
1046
this . subscriptions . add (
1045
1047
this . $model . listen ( ( ) => {
1046
1048
if ( ! hasInputData ( this . $inputData . get ( ) ) ) {
1049
+ this . resetEphemeralState ( ) ;
1047
1050
return ;
1048
1051
}
1049
1052
@@ -1057,6 +1060,7 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
1057
1060
this . subscriptions . add (
1058
1061
this . manager . stateApi . createStoreSubscription ( selectAutoProcess , ( autoProcess ) => {
1059
1062
if ( ! hasInputData ( this . $inputData . get ( ) ) ) {
1063
+ this . resetEphemeralState ( ) ;
1060
1064
return ;
1061
1065
}
1062
1066
if ( autoProcess ) {
@@ -1428,7 +1432,10 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase {
1428
1432
}
1429
1433
1430
1434
// 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
+ }
1432
1439
this . $imageState . set ( null ) ;
1433
1440
this . $pointType . set ( 1 ) ;
1434
1441
this . $invert . set ( false ) ;
0 commit comments