Skip to content

Commit

Permalink
fix MaterialID type err. cocos2d/cocos2d-x#20537
Browse files Browse the repository at this point in the history
  • Loading branch information
u0u0 committed Jun 21, 2020
1 parent 1339cd2 commit 5e2e425
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cocos/renderer/CCRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ void Renderer::drawBatchedTriangles()
_triBatchesToDraw[0].cmd = nullptr;

int batchesTotal = 0;
int prevMaterialID = -1;
uint32_t prevMaterialID = 0;
bool isValidMaterialID = false;
bool firstCommand = true;

_filledVertex = 0;
Expand All @@ -582,7 +583,7 @@ void Renderer::drawBatchedTriangles()
fillVerticesAndIndices(cmd, vertexBufferFillOffset);

// in the same batch ?
if (batchable && (prevMaterialID == currentMaterialID || firstCommand))
if (batchable && ((isValidMaterialID && prevMaterialID == currentMaterialID) || firstCommand))
{
CC_ASSERT((firstCommand || _triBatchesToDraw[batchesTotal].cmd->getMaterialID() == cmd->getMaterialID()) && "argh... error in logic");
_triBatchesToDraw[batchesTotal].indicesToDraw += cmd->getIndexCount();
Expand All @@ -603,7 +604,7 @@ void Renderer::drawBatchedTriangles()

// is this a single batch ? Prevent creating a batch group then
if (!batchable)
currentMaterialID = -1;
isValidMaterialID = false;
}

// capacity full ?
Expand All @@ -614,6 +615,7 @@ void Renderer::drawBatchedTriangles()
}

prevMaterialID = currentMaterialID;
isValidMaterialID = true;
firstCommand = false;
}
batchesTotal++;
Expand Down

0 comments on commit 5e2e425

Please sign in to comment.