Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not exactly sure what's going on (it depends on the implementation of Thread.delay, which I don't know). However, error 2 is <code>Unix.EAGAIN</code>, which represents a temporary shortage of kernel resources. As the name says, you should probably just try to do your Thread.delay again. If I use <code>try</code> ... <code>with</code> to catch the Unix.Unix_error exception I see no other errors except EAGAIN being delivered. If I just print a message and continue, the program seems to work. At least, it continues to echo characters to the window and doesn't crash. I'm working in OS X 10.7 (Lion). It might work differently for you.</p> <p><strong>Edit</strong></p> <p>Another possible problem with this code is that <code>Sys.time()</code> returns <em>processor</em> time, which only increases while the process is doing real computation. It doesn't increase while the process is waiting for input. This means that the delay is always invoked, even if you wait a long time between keypresses (it was confusing me for a while). It might be better to use <code>Unix.gettimeofday ()</code>, which returns wall clock time.</p> <p><strong>Edit 2</strong></p> <p>After some more research and testing, I believe that the <code>Unix.EAGAIN</code> error is telling you that the full delay was interrupted by some event. In your case the interrupting event is the arrival of a character (I believe). So if you want to wait the full time, you should replace the single call to <code>Thread.delay()</code> with a loop.</p> <p>This gives you something like the following for your main code:</p> <pre><code>let rec main (* state *) frame_time = (* Display state here. *) Input.get_input (); (* Advance state by one frame here. *) (* If less than 25ms have passed, delay until they have. *) let rec delay () = let duration = frame_time +. 0.025 -. Unix.gettimeofday () in if duration &gt; 0.0 then try Thread.delay duration with Unix.Unix_error (Unix.EAGAIN, _, _) -&gt; delay () in delay (); main (* next_state *) (Unix.gettimeofday ()) ;; let init = Graphics.open_graph " 800x500"; let start_time = (Unix.gettimeofday ()) in main (* start_state *) start_time ;; </code></pre> <p>(If you use Unix.select to do your delaying, you can remove the dependence on threads. But you might need them anyway for other reasons. The code would look the same except the error is EINTR rather than EAGAIN.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload