diff --git a/src/corelib/render.c b/src/corelib/render.c index c7338a4..80e9e40 100644 --- a/src/corelib/render.c +++ b/src/corelib/render.c @@ -141,12 +141,14 @@ void insert_drawcmd_at(size_t index, const drawcmd_t* cmd) { drawcmd_t* insertpoint = g_drawdata + index; drawcmd_t* dest = insertpoint + 1; size_t size = (size_t)(g_drawdata_endptr - g_drawdata); - size_t count = (size - index); - ++g_drawdata_endptr; - if(size > 0) - { - memmove(dest, insertpoint, count*sizeof(drawcmd_t)); + if(size > index) { + size_t count = (size - index); + if(size > 0) + { + memmove(dest, insertpoint, count*sizeof(drawcmd_t)); + } } + ++g_drawdata_endptr; memcpy(insertpoint, cmd, sizeof(drawcmd_t)); insertpoint->ui = _render_mode == 1; } @@ -162,7 +164,7 @@ void draw(const drawcmd_t* cmd) { med = floor((float)(top + bot) / 2); if(g_drawdata[med].ui < ui || g_drawdata[med].depth > cmd->depth) { bot = med+1; - } else if(g_drawdata[med].ui >= ui || g_drawdata[med].depth < cmd->depth) { + } else if(g_drawdata[med].ui > ui || g_drawdata[med].depth < cmd->depth) { top = med-1; } else { break;