Skip to content

Error when trying to use timers #235

@Taneb

Description

@Taneb

I'm trying to implement something using SDL timers, but I was getting a segfault whenever the timer first triggered. I've got this down to a fairly small failing example:

import Control.Monad (forever)
import qualified SDL

main :: IO ()
main = do
  SDL.initialize [SDL.InitTimer]
  ticker <- SDL.addTimer 1000 $ \d -> putStrLn "tick" >> return (SDL.Reschedule d)
  forever $ pure ()

This fails with

sdl-experiment: schedule: re-entered unsafely.
   Perhaps a 'foreign import unsafe' should be 'safe'?

This also occurs if I try to use the raw API, but does not occur if I try to port this to C.

Note that in my original larger example, I only got Segmentation fault (core dumped) as the error message, so there might be more than one thing going on here.

GHC 8.10.7, sdl2 Haskell library version 2.5.3.0, SDL2 C library 2.0.14, NixOS

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions