mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
gl_engine: fix memory out of bounds error in GlGpuBuffer
If buffer data is larger than memory alignment, need to make sure there is enough memory in current stage buffer
This commit is contained in:
parent
83151933a9
commit
a1c3a4a5ad
2 changed files with 5 additions and 5 deletions
|
@ -87,7 +87,7 @@ GlStageBuffer::~GlStageBuffer()
|
||||||
|
|
||||||
uint32_t GlStageBuffer::push(void *data, uint32_t size, bool alignGpuOffset)
|
uint32_t GlStageBuffer::push(void *data, uint32_t size, bool alignGpuOffset)
|
||||||
{
|
{
|
||||||
if (alignGpuOffset) alignOffset();
|
if (alignGpuOffset) alignOffset(size);
|
||||||
|
|
||||||
uint32_t offset = mStageBuffer.count;
|
uint32_t offset = mStageBuffer.count;
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ GLuint GlStageBuffer::getBufferId()
|
||||||
return mGpuBuffer->getBufferId();
|
return mGpuBuffer->getBufferId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlStageBuffer::alignOffset()
|
void GlStageBuffer::alignOffset(uint32_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t alignment = _getGpuBufferAlign();
|
uint32_t alignment = _getGpuBufferAlign();
|
||||||
|
@ -145,8 +145,8 @@ void GlStageBuffer::alignOffset()
|
||||||
|
|
||||||
uint32_t offset = alignment - mStageBuffer.count % alignment;
|
uint32_t offset = alignment - mStageBuffer.count % alignment;
|
||||||
|
|
||||||
if (mStageBuffer.count + offset > mStageBuffer.reserved) {
|
if (mStageBuffer.count + offset + size > mStageBuffer.reserved) {
|
||||||
mStageBuffer.grow(max(alignment, mStageBuffer.reserved));
|
mStageBuffer.grow(max(offset + size, mStageBuffer.reserved));
|
||||||
}
|
}
|
||||||
|
|
||||||
mStageBuffer.count += offset;
|
mStageBuffer.count += offset;
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
|
|
||||||
GLuint getBufferId();
|
GLuint getBufferId();
|
||||||
private:
|
private:
|
||||||
void alignOffset();
|
void alignOffset(uint32_t size);
|
||||||
private:
|
private:
|
||||||
GLuint mVao = 0;
|
GLuint mVao = 0;
|
||||||
unique_ptr<GlGpuBuffer> mGpuBuffer = {};
|
unique_ptr<GlGpuBuffer> mGpuBuffer = {};
|
||||||
|
|
Loading…
Add table
Reference in a new issue