fix infinite loop when expanding buffers
This commit is contained in:
parent
5c90eee84a
commit
a859814fda
2 changed files with 52 additions and 46 deletions
|
@ -59,30 +59,33 @@ instance Buffer IndexBuffer where
|
|||
unbind buf
|
||||
|
||||
write buf offset dat = do
|
||||
currentBufSize <- readTVarIO (iBufSize buf)
|
||||
whileM_
|
||||
(pure $ (fromIntegral offset + VS.length dat) *
|
||||
sizeOf (undefined :: StoreType IndexBuffer)
|
||||
> fromIntegral currentBufSize) $ do
|
||||
allocaArray
|
||||
(fromIntegral currentBufSize `div`
|
||||
sizeOf (undefined :: StoreType IndexBuffer))
|
||||
$ \ (ptr :: Ptr (StoreType IndexBuffer)) -> do
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.ReadFromBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
expand buf
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.WriteToBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
(do
|
||||
currentSize <- readTVarIO (iBufSize buf)
|
||||
pure $ (fromIntegral offset + VS.length dat) *
|
||||
sizeOf (undefined :: StoreType IndexBuffer)
|
||||
> fromIntegral currentSize)
|
||||
$ do
|
||||
currentBufSize <- readTVarIO (iBufSize buf)
|
||||
allocaArray
|
||||
(fromIntegral currentBufSize `div`
|
||||
sizeOf (undefined :: StoreType IndexBuffer))
|
||||
$ \ (ptr :: Ptr (StoreType IndexBuffer)) -> do
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.ReadFromBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
expand buf
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.WriteToBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
-- bind buffer, just to be safe
|
||||
bind buf
|
||||
let elemCount = fromIntegral offset + VS.length dat
|
||||
|
|
|
@ -89,30 +89,33 @@ instance Buffer VertexBuffer where
|
|||
unbind buf
|
||||
|
||||
write buf offset dat = do
|
||||
currentBufSize <- readTVarIO (vBufSize buf)
|
||||
whileM_
|
||||
(pure $ (fromIntegral offset + VS.length dat) *
|
||||
sizeOf (undefined :: StoreType VertexBuffer)
|
||||
> fromIntegral currentBufSize) $ do
|
||||
allocaArray
|
||||
(fromIntegral currentBufSize `div`
|
||||
sizeOf (undefined :: StoreType VertexBuffer))
|
||||
$ \ (ptr :: Ptr (StoreType VertexBuffer)) -> do
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.ReadFromBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
expand buf
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.WriteToBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
(do
|
||||
currentSize <- readTVarIO (vBufSize buf)
|
||||
pure $ (fromIntegral offset + VS.length dat) *
|
||||
sizeOf (undefined :: StoreType VertexBuffer)
|
||||
> fromIntegral currentSize)
|
||||
$ do
|
||||
currentBufSize <- readTVarIO (vBufSize buf)
|
||||
allocaArray
|
||||
(fromIntegral currentBufSize `div`
|
||||
sizeOf (undefined :: StoreType VertexBuffer))
|
||||
$ \ (ptr :: Ptr (StoreType VertexBuffer)) -> do
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.ReadFromBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
expand buf
|
||||
bind buf
|
||||
GL.bufferSubData
|
||||
(target buf)
|
||||
GL.WriteToBuffer
|
||||
0
|
||||
currentBufSize
|
||||
ptr
|
||||
-- bind buffer, just to be safe
|
||||
bind buf
|
||||
VS.unsafeWith dat $ \ ptr ->
|
||||
|
|
Loading…
Reference in a new issue