fix infinite loop when expanding buffers

This commit is contained in:
nek0 2020-12-23 07:20:23 +01:00
parent 5c90eee84a
commit a859814fda
2 changed files with 52 additions and 46 deletions

View File

@ -59,30 +59,33 @@ instance Buffer IndexBuffer where
unbind buf unbind buf
write buf offset dat = do write buf offset dat = do
currentBufSize <- readTVarIO (iBufSize buf)
whileM_ whileM_
(pure $ (fromIntegral offset + VS.length dat) * (do
sizeOf (undefined :: StoreType IndexBuffer) currentSize <- readTVarIO (iBufSize buf)
> fromIntegral currentBufSize) $ do pure $ (fromIntegral offset + VS.length dat) *
allocaArray sizeOf (undefined :: StoreType IndexBuffer)
(fromIntegral currentBufSize `div` > fromIntegral currentSize)
sizeOf (undefined :: StoreType IndexBuffer)) $ do
$ \ (ptr :: Ptr (StoreType IndexBuffer)) -> do currentBufSize <- readTVarIO (iBufSize buf)
bind buf allocaArray
GL.bufferSubData (fromIntegral currentBufSize `div`
(target buf) sizeOf (undefined :: StoreType IndexBuffer))
GL.ReadFromBuffer $ \ (ptr :: Ptr (StoreType IndexBuffer)) -> do
0 bind buf
currentBufSize GL.bufferSubData
ptr (target buf)
expand buf GL.ReadFromBuffer
bind buf 0
GL.bufferSubData currentBufSize
(target buf) ptr
GL.WriteToBuffer expand buf
0 bind buf
currentBufSize GL.bufferSubData
ptr (target buf)
GL.WriteToBuffer
0
currentBufSize
ptr
-- bind buffer, just to be safe -- bind buffer, just to be safe
bind buf bind buf
let elemCount = fromIntegral offset + VS.length dat let elemCount = fromIntegral offset + VS.length dat

View File

@ -89,30 +89,33 @@ instance Buffer VertexBuffer where
unbind buf unbind buf
write buf offset dat = do write buf offset dat = do
currentBufSize <- readTVarIO (vBufSize buf)
whileM_ whileM_
(pure $ (fromIntegral offset + VS.length dat) * (do
sizeOf (undefined :: StoreType VertexBuffer) currentSize <- readTVarIO (vBufSize buf)
> fromIntegral currentBufSize) $ do pure $ (fromIntegral offset + VS.length dat) *
allocaArray sizeOf (undefined :: StoreType VertexBuffer)
(fromIntegral currentBufSize `div` > fromIntegral currentSize)
sizeOf (undefined :: StoreType VertexBuffer)) $ do
$ \ (ptr :: Ptr (StoreType VertexBuffer)) -> do currentBufSize <- readTVarIO (vBufSize buf)
bind buf allocaArray
GL.bufferSubData (fromIntegral currentBufSize `div`
(target buf) sizeOf (undefined :: StoreType VertexBuffer))
GL.ReadFromBuffer $ \ (ptr :: Ptr (StoreType VertexBuffer)) -> do
0 bind buf
currentBufSize GL.bufferSubData
ptr (target buf)
expand buf GL.ReadFromBuffer
bind buf 0
GL.bufferSubData currentBufSize
(target buf) ptr
GL.WriteToBuffer expand buf
0 bind buf
currentBufSize GL.bufferSubData
ptr (target buf)
GL.WriteToBuffer
0
currentBufSize
ptr
-- bind buffer, just to be safe -- bind buffer, just to be safe
bind buf bind buf
VS.unsafeWith dat $ \ ptr -> VS.unsafeWith dat $ \ ptr ->