Skip to content
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

Crash in collision handler after removing a shape #6

Open
ssadler opened this issue Aug 24, 2014 · 0 comments
Open

Crash in collision handler after removing a shape #6

ssadler opened this issue Aug 24, 2014 · 0 comments

Comments

@ssadler
Copy link

ssadler commented Aug 24, 2014

If you have a separate collision handler, and you remove an overlapping shape from a space, that handler will (rightly) get called, but the shapes function will crash the program. It will attempt to lookup the shapes in the space from their Ptr values, but one of them is no longer there.

Example code:

import           Control.Monad.IO.Class
import           Data.StateVar as SV
import           Physics.Hipmunk as H


main = do
    H.initChipmunk
    space <- H.newSpace

    H.setDefaultCollisionHandler space $
        H.Handler { H.beginHandler     = Just hBegin
                  , H.preSolveHandler  = Nothing
                  , H.postSolveHandler = Nothing
                  , H.separateHandler  = Just hSeparate}

    b0 <- H.newBody 10 $ H.infinity
    s0 <- H.newShape b0 (H.Circle 10) 0
    H.position b0 SV.$= H.Vector 0 0

    b1 <- H.newBody 10 $ H.infinity
    s1 <- H.newShape b1 (H.Circle 10) 0
    H.position b1 SV.$= H.Vector 0 0

    H.spaceAdd space b0 >> H.spaceAdd space s0
    H.spaceAdd space b1 >> H.spaceAdd space s1

    step space 10

    H.spaceRemove space s0 >> H.spaceRemove space b0

  where
    hBegin = liftIO (putStrLn "collision") >> return True
    hSeparate = do
        (s0, s1) <- H.shapes
        liftIO $ do
            H.resetForces $ H.body s0
            H.resetForces $ H.body s1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant