Closed pixelzoom closed 6 months ago
@zepumph @samreid Can you provide insight into what "cannot set state while setting state" means, and what might typically cause this error?
This assertion is in PhetioStateEngine.ts setState
, which is the only place in the PhET-iO code base where I find isSettingStateProperty.value = true
. So I'm guessing that setState
is somehow being called recursively.
/**
* Sets the state from an object that represents the state.
*
* @param state - a json object (not a string) that specifies the values to set
* @param scopeTandem - returns if the given Tandem is in the scope of a (partial) state
*/
public setState( state: FullPhetioState, scopeTandem: Tandem ): void {
assert && assert( !this.isSettingStateProperty.value, 'cannot set state while setting state' );
I no longer see this in CT after resolving #239. But I'd still like to understand the nature of "cannot set state while setting state" errors.
My hypothesis/guess is that #239 assertion failed during a set state command, so the set state command did not exit cleanly. The wrapper did not get the message, and tried to set the state again. The sim, thinking it was still in the middle of a set state call, asserted out. Let's check in with @zepumph
@samreid is exactly right. There is a race condition between kicking off a new setState call and throwing the error from the sim. I'm happy to add in a crash-handler to prevent this, but mostly all that matters is what caused the problem from the sim side (bad holdConstant). Let's see if gas-properties throws an error like this again (moot if there isn't an underlying error to be triggered in gas-properties).
Thanks for the clarification. It sounds like addressing https://github.com/phetsims/gas-properties/issues/239 made this go away. So closing.
I've only seen this once in CT, for gases-intro, 5/10/2024, 3:29:53 AM. Note that further down in the message, the error reported in https://github.com/phetsims/gas-properties/issues/239 ("bad holdConstant state") appears.