-
Notifications
You must be signed in to change notification settings - Fork 9
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
assertion failure: percentConcentration out of range #210
Comments
Looks like the problem is with The steps to reproduce can now be truncated to:
As soon as a particle hits the bottom of the beaker, you'll see an assertion failure with message like this:
|
ConcentrationSolution defines this.soluteGramsProperty = new DerivedProperty(
[ this.soluteProperty, this.soluteAmountProperty, this.precipitateAmountProperty ],
function( solute, soluteAmount, precipitateAmount ) {
var soluteGrams = solute.molarMass * ( soluteAmount - precipitateAmount );
assert && assert( soluteGrams >= 0, 'invalid soluteGrams: ' + soluteGrams );
return soluteGrams;
} What I'm seeing is that the value of the assert && assert( soluteAmount === self.soluteAmountProperty.get(),
'soluteAmount=' + soluteAmount +
', soluteAmountProperty.get()=' + self.soluteAmountProperty.get() ); with this error message:
I do not understand what's going on here. Could this be happening because |
I asked:
Hmm, could be. If I remove |
Here's a simple example that's similar to what I have in ConcentrationSolution: var aProperty = new NumberProperty( 0 );
var bProperty = new DerivedProperty( [ aProperty ],
function( a ) { return a + 1; } );
var cProperty = new DerivedProperty( [ aProperty, bProperty ],
function( a, b ) {
assert && assert( a === aProperty.get(), 'a=' + a + ', aProperty.get()=' + aProperty.get() );
return a + b;
} ); Calling
If I replace This sure looks like a general problem to me. @samreid @jonathanolson can you have a look at the example above? Would you expect it to fail? If so, why? |
Ah... The problem is in this bit of DerivedProperty: 47 // @private Keep track of each dependency and only update the changed value, for speed
48 this.dependencyValues = dependencies.map( function( property ) {return property.get();} ); In the above example, when |
Here's the above example again, with a console message instead of an assertion: var aProperty = new NumberProperty( 0 );
var bProperty = new DerivedProperty( [ aProperty ],
function( a ) { return a + 1; } );
var cProperty = new DerivedProperty( [ aProperty, bProperty ],
function( a, b ) {
console.log( 'a=' + a + ' aProperty.get()=' + aProperty.get() );
return a + b;
} ); Console output demonstrating that
|
This is a serious problem in DerivedProperty. It's dependencies can be any array of Property - and that includes DerivedProperty, since it's a subtype of Property. And in some scenarios (like the one above) it's most definitely not calling the derivation function with the current values of all dependencies. |
I created an axon issue for the DerivedProperty problem, see phetsims/axon#146. |
This issues requires phetsims/axon#146 to be addressed. Blocked until then. |
This was resolved by phetsims/scenery#700 (comment), nothing sim-specific needs to be changed. @phet-steele please verify in master. |
@pixelzoom I think you meant phetsims/axon/issues/146? Anyway, this is fixed in master. |
@phet-steele You think correctly. Thanks for verifying. |
Steps to reproduce, from #209 (comment):
Assertion thrown:
ConcentrationSolution relevant code:
The text was updated successfully, but these errors were encountered: