Skip to content

Commit 5610909

Browse files
committed
Render3D: Improve robustness of Render3DColorOut buffer binding.
1 parent c5bd273 commit 5610909

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

desmume/src/OGLRender.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ size_t OpenGLRenderColorOut::BindRead32()
15761576
this->_currentReadyIdx = RENDER3D_RESOURCE_INDEX_NONE;
15771577
}
15781578

1579-
if ( (this->_currentReadingIdx32 != oldReadingIdx32) && (oldReadingIdx32 != RENDER3D_RESOURCE_INDEX_NONE) )
1579+
if ( (oldReadingIdx32 != RENDER3D_RESOURCE_INDEX_NONE) && (this->_currentReadingIdx32 != oldReadingIdx32) )
15801580
{
15811581
this->_state[oldReadingIdx32] = AsyncReadState_Free;
15821582

@@ -1588,6 +1588,12 @@ size_t OpenGLRenderColorOut::BindRead32()
15881588
}
15891589
}
15901590

1591+
// Do not proceed if we can't bind a buffer for reading.
1592+
if (this->_currentReadingIdx32 == RENDER3D_RESOURCE_INDEX_NONE)
1593+
{
1594+
return this->_currentReadingIdx32;
1595+
}
1596+
15911597
if (this->_pbo[this->_currentReadingIdx32] != 0)
15921598
{
15931599
if (this->_buffer32[this->_currentReadingIdx32] == NULL)
@@ -1870,6 +1876,12 @@ Render3DError OpenGLRenderColorOut::FillZero()
18701876
{
18711877
bufferIdx32 = this->_currentUsageIdx;
18721878
}
1879+
else
1880+
{
1881+
// No buffer was or is in use, so there is nothing to modify.
1882+
error = RENDER3DERROR_INVALID_BUFFER;
1883+
return error;
1884+
}
18731885

18741886
if (this->_willConvertColorOnGPU || (this->_texColorOut[bufferIdx32] != 0))
18751887
{
@@ -1882,8 +1894,7 @@ Render3DError OpenGLRenderColorOut::FillZero()
18821894

18831895
if ( (this->_pbo[bufferIdx32] != 0) &&
18841896
this->_willConvertColorOnGPU &&
1885-
(bufferIdx32 == this->_currentReadingIdx32) &&
1886-
(bufferIdx32 != RENDER3D_RESOURCE_INDEX_NONE) )
1897+
(bufferIdx32 == this->_currentReadingIdx32) )
18871898
{
18881899
glBindBuffer(GL_PIXEL_PACK_BUFFER, this->_pbo[bufferIdx32]);
18891900
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
@@ -1899,7 +1910,7 @@ Render3DError OpenGLRenderColorOut::FillZero()
18991910
glClear(GL_COLOR_BUFFER_BIT);
19001911
}
19011912

1902-
if ( (bufferIdx32 == this->_currentReadingIdx32) && (bufferIdx32 != RENDER3D_RESOURCE_INDEX_NONE) )
1913+
if (bufferIdx32 == this->_currentReadingIdx32)
19031914
{
19041915
this->_currentReadingIdx16 = bufferIdx32;
19051916
memset(this->_buffer16[bufferIdx32], 0, this->_framebufferSize16);

desmume/src/rasterize.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,8 +1587,14 @@ Render3DError SoftRasterizerColorOut::FillZero()
15871587
{
15881588
bufferIdx = this->_currentUsageIdx;
15891589
}
1590+
else
1591+
{
1592+
// No buffer was or is in use, so there is nothing to modify.
1593+
error = RENDER3DERROR_INVALID_BUFFER;
1594+
return error;
1595+
}
15901596

1591-
if ( (bufferIdx != RENDER3D_RESOURCE_INDEX_NONE) && (this->_buffer32[bufferIdx] != NULL) )
1597+
if (this->_buffer32[bufferIdx] != NULL)
15921598
{
15931599
memset(this->_buffer32[bufferIdx], 0, this->_framebufferSize32);
15941600
}

desmume/src/render3D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ size_t Render3DColorOut::BindRead32()
385385
this->_currentReadyIdx = RENDER3D_RESOURCE_INDEX_NONE;
386386
}
387387

388-
if ( (this->_currentReadingIdx32 != oldReadingIdx32) && (oldReadingIdx32 != RENDER3D_RESOURCE_INDEX_NONE) )
388+
if ( (oldReadingIdx32 != RENDER3D_RESOURCE_INDEX_NONE) && (this->_currentReadingIdx32 != oldReadingIdx32) )
389389
{
390390
this->_state[oldReadingIdx32] = AsyncReadState_Free;
391391
}

0 commit comments

Comments
 (0)