Skip to content

Commit

Permalink
fix: naming and memory bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anut-py committed Apr 9, 2024
1 parent cba2af2 commit cfff116
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/Raylib/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,11 @@ isFileDropped :: IO Bool
isFileDropped = toBool <$> c'isFileDropped

loadDroppedFiles :: IO FilePathList
loadDroppedFiles = c'loadDroppedFiles >>= pop
loadDroppedFiles = do
ptr <- c'loadDroppedFiles
val <- peek ptr
c'unloadDroppedFiles ptr
return val

getFileModTime :: String -> IO Integer
getFileModTime fileName = fromIntegral <$> withCString fileName c'getFileModTime
Expand Down
9 changes: 4 additions & 5 deletions src/Raylib/Core/Models.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ import Raylib.Types
Vector2,
Vector3,
)
import Prelude hiding (length)

$( genNative
[ ("c'drawLine3D", "DrawLine3D_", "rl_bindings.h", [t|Ptr Vector3 -> Ptr Vector3 -> Ptr Color -> IO ()|], False),
Expand Down Expand Up @@ -286,13 +285,13 @@ drawTriangleStrip3D :: [Vector3] -> Int -> Color -> IO ()
drawTriangleStrip3D points pointCount color = withFreeableArray points (\p -> withFreeable color (c'drawTriangleStrip3D p (fromIntegral pointCount)))

drawCube :: Vector3 -> Float -> Float -> Float -> Color -> IO ()
drawCube position width height length color = withFreeable position (\p -> withFreeable color (c'drawCube p (realToFrac width) (realToFrac height) (realToFrac length)))
drawCube position width height _length color = withFreeable position (\p -> withFreeable color (c'drawCube p (realToFrac width) (realToFrac height) (realToFrac _length)))

drawCubeV :: Vector3 -> Vector3 -> Color -> IO ()
drawCubeV position size color = withFreeable position (\p -> withFreeable size (withFreeable color . c'drawCubeV p))

drawCubeWires :: Vector3 -> Float -> Float -> Float -> Color -> IO ()
drawCubeWires position width height length color = withFreeable position (\p -> withFreeable color (c'drawCubeWires p (realToFrac width) (realToFrac height) (realToFrac length)))
drawCubeWires position width height _length color = withFreeable position (\p -> withFreeable color (c'drawCubeWires p (realToFrac width) (realToFrac height) (realToFrac _length)))

drawCubeWiresV :: Vector3 -> Vector3 -> Color -> IO ()
drawCubeWiresV position size color = withFreeable position (\p -> withFreeable size (withFreeable color . c'drawCubeWiresV p))
Expand Down Expand Up @@ -430,10 +429,10 @@ genMeshPoly :: Int -> Float -> WindowResources -> IO Mesh
genMeshPoly sides radius wr = c'genMeshPoly (fromIntegral sides) (realToFrac radius) >>= pop >>= (`storeMeshData` wr)

genMeshPlane :: Float -> Float -> Int -> Int -> WindowResources -> IO Mesh
genMeshPlane width length resX resZ wr = c'genMeshPlane (realToFrac width) (realToFrac length) (fromIntegral resX) (fromIntegral resZ) >>= pop >>= (`storeMeshData` wr)
genMeshPlane width _length resX resZ wr = c'genMeshPlane (realToFrac width) (realToFrac _length) (fromIntegral resX) (fromIntegral resZ) >>= pop >>= (`storeMeshData` wr)

genMeshCube :: Float -> Float -> Float -> WindowResources -> IO Mesh
genMeshCube width height length wr = c'genMeshCube (realToFrac width) (realToFrac height) (realToFrac length) >>= pop >>= (`storeMeshData` wr)
genMeshCube width height _length wr = c'genMeshCube (realToFrac width) (realToFrac height) (realToFrac _length) >>= pop >>= (`storeMeshData` wr)

genMeshSphere :: Float -> Int -> Int -> WindowResources -> IO Mesh
genMeshSphere radius rings slices wr = c'genMeshSphere (realToFrac radius) (fromIntegral rings) (fromIntegral slices) >>= pop >>= (`storeMeshData` wr)
Expand Down
2 changes: 1 addition & 1 deletion src/Raylib/Types/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ p'vrStereoConfig'scaleIn :: Ptr VrStereoConfig -> Ptr CFloat
p'vrStereoConfig'scaleIn = (`plusPtr` 296)

data FilePathList = FilePathList
{ filePathlist'capacity :: Integer,
{ filePathList'capacity :: Integer,
filePathList'paths :: [String]
}
deriving (Eq, Show)
Expand Down

0 comments on commit cfff116

Please sign in to comment.