Is there a way to finish "normally" animate / simulate?

16 views
Skip to first unread message

Evgenii Cherkashin

unread,
Oct 27, 2022, 8:49:00 AM10/27/22
to Haskell Gloss
Hello,

I don't see a way to make the IO action / function to return. I am
currently calling os exit from the step function when I need to
terminate the animation, but this has a number of downsides. Not least,
it causes ghci to terminate, which makes debugging/developing under ghci
more difficult.

I could imagine that raising an exception in the step function, and
catching it in the calling code might work? Would it be cleaner though
to have the step function return a Maybe {Picture|model}, and terminate
the outer loop when it returns Nothing?

Am I missing something obvious?

Thanks,

Eugene

Eugene Crosser

unread,
Nov 1, 2022, 6:15:32 AM11/1/22
to Haskell Gloss
On Thursday, 27 October 2022 at 14:49:00 UTC+2 Eugene Crosser wrote:
I could imagine that raising an exception in the step function, and
catching it in the calling code might work?
And it actually does not work! This code
```
  catch (animateFixedIO screenmode black (step beg end datap fh) ctrl)
        (\e -> putStrLn $ "caught exception" ++ (show (e :: FinishException)))
  putStrLn $ "After animation"
```
behaves as if `catch` was not used when the step function runs `throwIO`. I just get
```
<interactive>: Finish
<interactive>: interrupted
<interactive>: warning: too many hs_exit()s
```
under ghci, and
```
animate: Finish
```
when running compiled program.
So, any advice please?

Eugene

Jørn Lode

unread,
Nov 2, 2022, 7:50:32 PM11/2/22
to Haskell Gloss
I think it's just an oversight (or a consequence of the API being designed to be very simply -- in this case, too simple for your use case). I patched gloss so I was able to exit by returning `Nothing` from the event handler function: https://github.com/boblehest/gloss/commit/2031a3a4afd980ef5d0130ec55d8ee8b48004683 . (In the previous commits, you can see I also patched it to assume that I'm using freeGLUT, because GLUT doesn't provide a way to exit cleanly anyway).
Reply all
Reply to author
Forward
0 new messages