My problem is a fringe problem- I'm actually hoping it is something out of my control because I have no idea where it happened, or how.
When running in a browser, is it possible for execution of a block of code to get interrupted , and/or the statements executed out of order, by something the user does with the computer?
I have a situation where I'm recording elapsed time across four variables in a row.
I can see how those times might vary by a few microseconds, but today I hit a case in a webGL game that someone was running (no idea what computer, OS, or browser they were using) and the times came out several seconds apart.
Imagine the situation, in reference to the code below, where stimulus_time is >= stimulus max time and g1=g2=g3=g4 = false. Latency_timer is a stopwatch. As soon as mode changes in the last line, this code will not be encountered again until the next "trial". This is the last opportunity for l1 to l4 to get set if they have not already been set on a particular trial. If they have already been set, they'd be less than stimulus max time (which was 14 seconds)
if (stimulus_time >= stimulus_max_time)
{
if (!g1)
{
l1 = latency_timer.elapsedmilliseconds*.001;
g1 = true;
}
if (!g2)
{
l2 = latency_timer.elapsedmilliseconds*.001;
g2 = true;
}
if (!g3)
{
l3 = latency_timer.elapsedmilliseconds*.001;
g3 = true;
}
if (!g4)
{
l4 = latency_timer.elapsedmilliseconds*.001;
g4 = true;
}
mode = Modes.context_change;
}
So far this has worked out just fine. Its given what appears to be correct data over hundreds of trials across many different users. If the "if (stimulus_timer >= stimulus_max_time)" is true, and all the bools are false, then l1 to l4 are always the same out to at least 2 decimals (e.g., 14, 14.02) thats as far as I print in my data file anyway. But today,on one trial for one person I got 21.24, 15.67, 16.55, and 17.63 for l1 to l4.
This is a fringe case- I've had 15 anonymous people run this game to completion, and there are 41 times that this code gets executed per person, and it's been accurate 764 out of 765 times.
↧