Added handle debug checks.

This commit is contained in:
Branimir Karadžić 2015-02-25 19:46:10 -08:00
parent 26e96b0489
commit b80edd19ff
2 changed files with 13 additions and 1 deletions

View file

@ -19,6 +19,14 @@ namespace bgfx
# define BGFX_CHECK_RENDER_THREAD() # define BGFX_CHECK_RENDER_THREAD()
#endif // BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS #endif // BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS
#define BGFX_CHECK_HANDLE(_handle, _max) \
BX_CHECK(isValid(_handle) \
&& _handle.idx < _max \
, "Invalid handle. %d (< %d " #_max ")" \
, _handle.idx \
, _max \
);
#if BX_PLATFORM_ANDROID #if BX_PLATFORM_ANDROID
::ANativeWindow* g_bgfxAndroidWindow = NULL; ::ANativeWindow* g_bgfxAndroidWindow = NULL;
@ -2749,18 +2757,21 @@ again:
void setUniform(UniformHandle _handle, const void* _value, uint16_t _num) void setUniform(UniformHandle _handle, const void* _value, uint16_t _num)
{ {
BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_MAIN_THREAD();
BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_UNIFORMS);
s_ctx->setUniform(_handle, _value, _num); s_ctx->setUniform(_handle, _value, _num);
} }
void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices)
{ {
BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_MAIN_THREAD();
BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_INDEX_BUFFERS);
s_ctx->setIndexBuffer(_handle, _firstIndex, _numIndices); s_ctx->setIndexBuffer(_handle, _firstIndex, _numIndices);
} }
void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices)
{ {
BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_MAIN_THREAD();
BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS);
s_ctx->setIndexBuffer(_handle, _firstIndex, _numIndices); s_ctx->setIndexBuffer(_handle, _firstIndex, _numIndices);
} }
@ -2785,12 +2796,14 @@ again:
void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices)
{ {
BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_MAIN_THREAD();
BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_VERTEX_BUFFERS);
s_ctx->setVertexBuffer(_handle, _startVertex, _numVertices); s_ctx->setVertexBuffer(_handle, _startVertex, _numVertices);
} }
void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices) void setVertexBuffer(DynamicVertexBufferHandle _handle, uint32_t _numVertices)
{ {
BGFX_CHECK_MAIN_THREAD(); BGFX_CHECK_MAIN_THREAD();
BGFX_CHECK_HANDLE(_handle, BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS);
s_ctx->setVertexBuffer(_handle, _numVertices); s_ctx->setVertexBuffer(_handle, _numVertices);
} }

View file

@ -1370,7 +1370,6 @@ namespace bgfx
void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) void setVertexBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices)
{ {
BX_CHECK(_handle.idx < BGFX_CONFIG_MAX_VERTEX_BUFFERS, "Invalid vertex buffer handle. %d (< %d)", _handle.idx, BGFX_CONFIG_MAX_VERTEX_BUFFERS);
m_draw.m_startVertex = _startVertex; m_draw.m_startVertex = _startVertex;
m_draw.m_numVertices = _numVertices; m_draw.m_numVertices = _numVertices;
m_draw.m_vertexBuffer = _handle; m_draw.m_vertexBuffer = _handle;