@@ -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 );
0 commit comments