main :: IO ()
main = bracket
  (do
    !b <- ovr_Initialize
    !ghmd <- initGLFW winSize "oculus test" False
    return (b,ghmd))
  (\ (_,ghmd) -> do
            ovr_Shutdown 
            exitGLFW ghmd
            traceIO "exit")
  (\ (b,ghmd) -> if b 
    then do
      traceIO "init OK"
      bracket
        (do
          !maxIdx <- ovrHmd_Detect
          traceIO $ "detect = " ++ show maxIdx
          !hmd <- if maxIdx > 0 
            then ovrHmd_Create (maxIdx - 1)
            else Just <$> ovrHmd_CreateDebug ovrHmd_DK2
          return hmd)
        (\ hmd' -> if isJust hmd' 
            then do
              ovrHmd_Destroy $ fromJust hmd'
              traceIO "destroy hmd"
            else do
              traceIO "hmd is Null"
              return ())
        (mainProcess ghmd)
    else traceIO "init NG")
main :: IO ()
main = bracket
  (do
    !b <- ovr_Initialize
    !ghmd <- initGLFW winSize "oculus test" False
    return (b,ghmd))
  (\ (_,ghmd) -> do
            ovr_Shutdown 
            exitGLFW ghmd
            traceIO "exit")
  (\ (b,ghmd) -> if b 
    then do
      traceIO "init OK"
      bracket
        (do
          !maxIdx <- ovrHmd_Detect
          traceIO $ "detect = " ++ show maxIdx
          !hmd <- if maxIdx > 0 
            then ovrHmd_Create (maxIdx - 1)
            else Just <$> ovrHmd_CreateDebug ovrHmd_DK2
          return hmd)
        (\ hmd' -> if isJust hmd' 
            then do
              ovrHmd_Destroy $ fromJust hmd'
              traceIO "destroy hmd"
            else do
              traceIO "hmd is Null"
              return ())
        (mainProcess ghmd)
    else traceIO "init NG")
main = bracket
  (do
    !b <- ovr_Initialize
    !ghmd <- initGLFW winSize "oculus test" False
    return (b,ghmd))
  (\ (_,ghmd) -> do
            ovr_Shutdown 
            exitGLFW ghmd
            traceIO "exit")
  (\ (b,ghmd) -> if b 
    then do
      traceIO "init OK"
      bracket
        (do
          !maxIdx <- ovrHmd_Detect
          traceIO $ "detect = " ++ show maxIdx
          !hmd <- if maxIdx > 0 
            then ovrHmd_Create (maxIdx - 1)
            else Just <$> ovrHmd_CreateDebug ovrHmd_DK2
          return hmd)
        (\ hmd' -> if isJust hmd' 
            then do
              ovrHmd_Destroy $ fromJust hmd'
              traceIO "destroy hmd"
            else do
              traceIO "hmd is Null"
              return ())
        (mainProcess ghmd)
    else traceIO "init NG")