-
Notifications
You must be signed in to change notification settings - Fork 6
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
dt is sometimes zero #171
Comments
Does this happen on all browsers? |
I noticed this issue in Win8/Chrome Version 38.0.2125.101 m (64-bit) |
I updated and also saw this problem once in Chrome Version 38.0.2125.104 m (64-bit) |
This sounds like it's either (a) vestigial or (b) potentially serious. Assigning to @jonathanolson. |
Will try to reproduce. |
I've spent 10 minutes banging on the sim and I'm unable to reproduce (Win7/Chrome). Added debugger in Sim.js step if dt was zero, I'd recommend @jbphet add the debugger statement and see if you can still trigger it. |
I was able to duplicate this, but not during normal sim usage. I was able to make it happen when I had the developer tools open and was changing the size of the tools window, sliding the divider either right or left. The attached screen shots show the output. I also tried this with a debugger statement, and the statement was indeed hit, demonstrating that this isn't just a rounding issue when printing the value. The code that was added in the BalanceModel.step function looked like this (including the debug statement): if ( dt < 0.0083333 || dt > 0.025 ){
console.log( 'dt off by more than 50% of nominal, value = ' + dt );
if ( dt === 0 ){
debugger;
}
} |
Assigning back to @jonathanolson to decide if this is indeed "potentially serious" and should be addressed. The sim handles it just fine, and I assume most sims would, so it may be a non-issue. It's just a little odd that it happens at all. By the way, the test environment where this was reproduced was Win7+Chrome43. |
Will check to make sure resizing doesn't cause sim steps. |
Reproduced with Chrome/Mac, had two animation frames with the exact same timestamp (1432926900170) that were naturally generated. Looks like resizing causes more animation frames to be rendered (probably on each resize), so if the sim JS executes quickly enough, there can be many low-DT frames. Because there is a resize, the ScreenView transform will change, and the view step may be expected to be called after that, so although I'd like to prevent 0-DT frames from even being stepped, I think we need to anyways. Thus in general, sims should be prepared to handle frame DTs that are zero. |
Anything else to do here @pixelzoom, @samreid or @jbphet? |
I'll go ahead and close. I'm fine with the implementation requirement that sims need to be able to handle zero values for dt. |
Sure, sims should handle small dt, but shouldn't we just add a line of logic in joist: if (dt>0){
step();
} ? Then we can avoid any required corner-case handling in sim code? |
@jonathanolson said:
Searching for "/ dt", I find 2 sims that will fail with divide-by-zero errors: balloons-and-static-electricity, faradays-law. (Don't know if those sims are testing for "dt > 0" somewhere.) |
+1 for @samreid suggestion to address this in joist. Unless someone can explain the value of calling step when dt is zero? |
As noted re: skipping step() if dt === 0:
So we would skip model/view steps, do we also skip updateDisplay() and have the sim NOT update on window resize? Seems sketchy to me. If we don't skip updateDisplay(), then because the ScreenView transform was changed, other view bits may have changed and would expect model/view updates (view.step() in particular). I assumed every time we redraw the sim, we'll have a view.step(). |
OK, makes sense. Then we need to take a look at balloons-and-static-electricity and faradays-law (and possibly other sims?) |
Yes, probably for most sims. Molecule Shapes might also not handle dt=0 gracefully. |
I'd like to update my proposal to consider skipping the model.step() if it's 0, but still doing the view step. Usually view steps don't need the DT as much, and generally models shouldn't change if there's a 0-time DT. Thoughts? |
@jonathanolson's suggestion #171 (comment) seems like a good solution. |
Sounds reasonable to me. Regardless, my approach will be to program defensively :) |
Committed the proposed change. Sims that use DT in the view step (ignoring empty implementations): I'll check through all usages to ensure that we're fine before closing the issue. There are also a ton of copy-pasted empty step functions, which aren't needed (if the function doesn't exist, it won't be called). Should we remove those? |
All usages look safe, although there are a lot of step functions that are empty or that aren't part of a view and ignore their DT parameter. Will note in meeting agenda about possible cleanup. |
Those empty step functions are probably being propagated from simula-rasa. I'll add a comment in simula-rasa that say something like "delete if not used". |
… step functions should be deleted
"Called by the animation loop. Optional" is the comment in simula-rasa, and it appears 39 times in sim code. So yes, this is where the empty step functions are coming from. |
At today's meeting, we decided to remove the empty step functions in existing code, and that @samreid would do it. |
OK I removed the empty blocks above. @pixelzoom anything else to do here? |
I think the covers it. Closing. |
@jbphet noticed in Balancing Act that joist sometimes sends out dt=0 in the step function. It generally appears to be correlated with when the cursor changes to a hand/arrow. I have reproduced the problem on my machine (though it appears less frequently than on @jbphet machine). Perhaps related to phetsims/scenery#275
The text was updated successfully, but these errors were encountered: