Skip to content

Commit

Permalink
fix material id type err
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongfq committed Jun 28, 2020
1 parent c91a90f commit 42dd179
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions frameworks/cocos2d-x/cocos/renderer/CCRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,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 @@ -587,7 +588,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 @@ -608,7 +609,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 @@ -619,6 +620,7 @@ void Renderer::drawBatchedTriangles()
}

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

0 comments on commit 42dd179

Please sign in to comment.