宝爷Debug小记——Cocos2d-x(3.13之前的版本)底层BUG导致Spine渲染花屏
最近在工作中碰到不少棘手的BUG,其中的一个是Spine骨骼的渲染花屏,在战斗中派发出大量士兵之后有概率出现花屏闪烁(如下图所示),这种莫名奇妙且难以重现的BUG最为蛋疼。
n)dk)%25n5h.jpg)
n)dk)%25n5h.jpg)

static int skiptype = ;
void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
SkeletonBatch* batch = SkeletonBatch::getInstance(); for (auto t : _curTriangles)
{
TrianglesMgr::getInstance()->freeTriangles(t);
}
_curTriangles.clear();
_triCmds.clear(); Color3B nodeColor = getColor();
_skeleton->r = nodeColor.r / (float);
_skeleton->g = nodeColor.g / (float);
_skeleton->b = nodeColor.b / (float);
_skeleton->a = getDisplayedOpacity() / (float); Color4F color;
AttachmentVertices* attachmentVertices = nullptr;
for (int i = , n = _skeleton->slotsCount; i < n; ++i) {
spSlot* slot = _skeleton->drawOrder[i];
if (!slot->attachment) continue;
if (slot->attachment->type == skiptype) continue;
switch (slot->attachment->type) {
case SP_ATTACHMENT_REGION: {
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices);
attachmentVertices = getAttachmentVertices(attachment);
color.r = attachment->r;
color.g = attachment->g;
color.b = attachment->b;
color.a = attachment->a;
break;
}
case SP_ATTACHMENT_MESH: {
spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
spMeshAttachment_computeWorldVertices(attachment, slot, _worldVertices);
attachmentVertices = getAttachmentVertices(attachment);
color.r = attachment->r;
color.g = attachment->g;
color.b = attachment->b;
color.a = attachment->a;
break;
}
default:




void Renderer::processRenderCommand(RenderCommand* command)
{
auto commandType = command->getType();
if( RenderCommand::Type::TRIANGLES_COMMAND == commandType)
{
// flush other queues
flush3D(); auto cmd = static_cast<TrianglesCommand*>(command); // flush own queue when buffer is full
if(_filledVertex + cmd->getVertexCount() > VBO_SIZE || _filledIndex + cmd->getIndexCount() > INDEX_VBO_SIZE)
{
CCASSERT(cmd->getVertexCount()>= && cmd->getVertexCount() < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command");
CCASSERT(cmd->getIndexCount()>= && cmd->getIndexCount() < INDEX_VBO_SIZE, "VBO for index is not big enough, please break the data down or use customized render command");
drawBatchedTriangles();
} // queue it
_queuedTriangleCommands.push_back(cmd);
_filledIndex += cmd->getIndexCount();
_filledVertex += cmd->getVertexCount();
}
// 增加一些调试用的静态变量
static bool __dbg = false;
static bool __deepDbg = false;
static int __cmdCount = ;
static int __curCmdCount = ;
static int __idxCount = ;
static int __vexCount = ;
static int __maxidx = ;
void Renderer::fillVerticesAndIndices(const TrianglesCommand* cmd)
{
memcpy(&_verts[_filledVertex], cmd->getVertices(), sizeof(V3F_C4B_T2F) * cmd->getVertexCount()); // fill vertex, and convert them to world coordinates
const Mat4& modelView = cmd->getModelView();
for(ssize_t i=; i < cmd->getVertexCount(); ++i)
{
modelView.transformPoint(&(_verts[i + _filledVertex].vertices));
// 打印所有顶点的xyz和纹理uv
if(__dbg && __deepDbg)
{
CCLOG("vertex %d is xyz %.2f,%.2f,%.2f uv %.2f,%.2f", i + _filledVertex - __vexCount,_verts[i + _filledVertex].vertices.x,
_verts[i + _filledVertex].vertices.y, _verts[i + _filledVertex].vertices.z,
_verts[i + _filledVertex].texCoords.u, _verts[i + _filledVertex].texCoords.v);
}
} // fill index
const unsigned short* indices = cmd->getIndices();
for(ssize_t i=; i< cmd->getIndexCount(); ++i)
{
_indices[_filledIndex + i] = _filledVertex + indices[i];
if (__dbg)
{
if (__maxidx < _indices[_filledIndex + i])
{
__maxidx = _indices[_filledIndex + i];
}
if (__deepDbg)
{
CCLOG("index %d is %d", _filledIndex + i - __idxCount, _indices[_filledIndex + i] - __vexCount);
}
}
} _filledVertex += cmd->getVertexCount();
_filledIndex += cmd->getIndexCount();
} void Renderer::drawBatchedTriangles()
{
if(_queuedTriangleCommands.empty())
return; CCGL_DEBUG_INSERT_EVENT_MARKER("RENDERER_BATCH_TRIANGLES"); if (__dbg)
{
__vexCount = ;
__idxCount = ;
__curCmdCount = ;
}
_filledVertex = ;
_filledIndex = ; /************** 1: Setup up vertices/indices *************/ _triBatchesToDraw[].offset = ;
_triBatchesToDraw[].indicesToDraw = ;
_triBatchesToDraw[].cmd = nullptr; int batchesTotal = ;
int prevMaterialID = -;
bool firstCommand = true; for(auto it = std::begin(_queuedTriangleCommands); it != std::end(_queuedTriangleCommands); ++it)
{
const auto& cmd = *it;
auto currentMaterialID = cmd->getMaterialID();
const bool batchable = !cmd->isSkipBatching();
if (__dbg)
{
if (__curCmdCount % __cmdCount == )
{
CCLOG("begin %d =====================================", __curCmdCount / __cmdCount);
__vexCount = _filledVertex;
__idxCount = _filledIndex;
}
++__curCmdCount;
}
fillVerticesAndIndices(cmd); // in the same batch ?
if (batchable && (prevMaterialID == currentMaterialID || firstCommand))
{
CC_ASSERT(firstCommand || _triBatchesToDraw[batchesTotal].cmd->getMaterialID() == cmd->getMaterialID() && "argh... error in logic");
_triBatchesToDraw[batchesTotal].indicesToDraw += cmd->getIndexCount();
_triBatchesToDraw[batchesTotal].cmd = cmd;
}
else
{
// is this the first one?
if (!firstCommand) {
batchesTotal++;
_triBatchesToDraw[batchesTotal].offset = _triBatchesToDraw[batchesTotal-].offset + _triBatchesToDraw[batchesTotal-].indicesToDraw;
} _triBatchesToDraw[batchesTotal].cmd = cmd;
_triBatchesToDraw[batchesTotal].indicesToDraw = (int) cmd->getIndexCount(); // is this a single batch ? Prevent creating a batch group then
if (!batchable)
currentMaterialID = -;
} // capacity full ?
if (batchesTotal + >= _triBatchesToDrawCapacity) {
_triBatchesToDrawCapacity *= 1.4;
_triBatchesToDraw = (TriBatchToDraw*) realloc(_triBatchesToDraw, sizeof(_triBatchesToDraw[]) * _triBatchesToDrawCapacity);
} prevMaterialID = currentMaterialID;
firstCommand = false;
}
batchesTotal++;
if (__dbg)
{
CCLOG("MAX IDX %d", __maxidx);
}
__dbg = false;
for (int i=; i<batchesTotal; ++i)
{
CC_ASSERT(_triBatchesToDraw[i].cmd && "Invalid batch");
_triBatchesToDraw[i].cmd->useMaterial();
glDrawElements(GL_TRIANGLES, (GLsizei) _triBatchesToDraw[i].indicesToDraw, GL_UNSIGNED_SHORT, (GLvoid*) (_triBatchesToDraw[i].offset*sizeof(_indices[])) );
_drawnBatches++;
_drawnVertices += _triBatchesToDraw[i].indicesToDraw;
}
宝爷Debug小记——Cocos2d-x(3.13之前的版本)底层BUG导致Spine渲染花屏的更多相关文章
- Archlinux安装指南~小米笔记本Air 13.3英寸版本
小米笔记本Air 13.3英寸版本,配置为:Intel Core i5-6200U处理器.8GB内存.256GB固态硬盘.NVIDIA GeForce 940MX独立显卡,13.3英寸1920X108 ...
- Node程序debug小记
有时候,所见并不是所得,有些包,你需要去翻他的源码才知道为什么会这样. 背景 今天调试一个程序,用到了一个很久之前的NPM包,名为formstream,用来将form表单数据转换为流的形式进行接口调用 ...
- XE7 & IOS开发之开发账号(1):开发证书、AppID、设备、开发授权profile的申请使用,附Debug真机调试演示(XCode所有版本通用,有图有真相)
网上能找到的关于Delphi XE系列的移动开发的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 注意,以下讨论都是以&q ...
- GoldenGate针对OEM 13.1的版本发布
OGG 针对OEM(Oracle Enterprise Manager) 13.1的插件已经可以从这里下载: http://www.oracle.com/technetwork/middleware/ ...
- 解决IntelliJ IDEA 13更新FindBugs 0.9.993时JRE版本过低导致启动失败问题
今晚更新FindBugs 0.9.992(FindBugs 2)至FindBugs 0.9.993(FindBugs 3)后,按要求重启IntelliJ IDEA 13.本想看看更新后多了哪些功能,结 ...
- Archlinux配置~小米笔记本Air 13.3英寸版本
1 .zsh echo $ SHELL \\查看当前正在使用shell: pacman -S zsh zsh-syntax-highlighting git wget wget https://raw ...
- 精华阅读第 13 期 |常见的八种导致 APP 内存泄漏的问题
本期是移动开发精英俱乐部的第13期文章,都是以技术为主,所以这里就不过多的进行赘述了,我们直接看干货内容吧!本文系ITOM管理平台OneAPM整理. 实际项目中的MVVM(积木)模式–序章 导读:开篇 ...
- cocos2d 2.0和UIKit混合编程, Push CCDirector的时候出现黑屏的天坑
症状 使用cocos2d 2.0和UIKit混合编程, 有一块用cocos2d编写的小程序, 将CCDirector push到一个UINavigationController里面. 虽然事先在后台初 ...
- RUEI 13.1.1版本在OEL 5.7上的安装
准备工作 ntp的工作和同步 /sbin/chkconfig --list | grep ntpd ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off /sb ...
随机推荐
- layer插件
最近在做公司的官网,其中有用到layer这款插件,以前没有接触过,不过学下来觉得好用好学.下面分享一下我的学习心得. layer是web弹出层组件.在官网下载好layer后,把他部署到你的项目文件中( ...
- 手把手教你做个AR涂涂乐
前段时间公司有一个AR涂涂乐的项目,虽然之前接触过AR也写过小Demo,但是没有完整开发过AR项目.不过经过1个多星期的学习,现在已经把项目相关的技术都学会了,在此向互联网上那些乐于分享的程序员前辈们 ...
- C++获取字符cin,getchar,get,getline的区别
原创作品,转载请注明来源:http://www.cnblogs.com/shrimp-can/p/5241544.html 1.cin>> 1)最常见的是获取输入的一个字符或数字,如 in ...
- Power BI Embedded 与 Bot Framework 结合的AI解决方案
最近最热门的话题莫过于AI了,之前我做过一片讲 BOTFRAMEWORK和微信 相结合的帖子 如何将 Microsoft Bot Framework 链接至微信公共号 我想今天基于这个题目扩展一下,P ...
- h5 做app时和原生交互的小常识。
距离上次随笔或许有半年了吧,最近在用hybrid模式开发移动app,所以就简单的说说用h5技术开发app时候,做原生交互的几个小常识: 一.拨打电话或者发送短信: <a href="t ...
- 【Egret】实现web页面操作PC端本地文件操作
Egret 实现web页面操作PC端本地文件操作: http://edn.egret.com/cn/book/page/pid/181 //------------------------------ ...
- 老李分享:接电话之uiautomator 1
老李分享:接电话之uiautomator poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:9 ...
- java 解压 zip 包并删除
需求是这样的, 在服务器上有 运营上传的zip 包,内容是用户的照片,我需要做的是 获取这些照片上传,并保存到 数据库. 这里面的 上传照片,保存数据库都不难,主要问题是解压zip包,和删除zip ...
- JavaScript学习总结(一)DOM文档对象模型
一.文档(D) 一个网页运行在浏览器中,他就是一个文档对象. 二.对象(O) "对象"是一种自足的数据集合.与某个特定对象相关联的变量被称为这个对象的属性,只能通过某个对象调用的函 ...
- Spark入门实战
星星之火,可以燎原 Spark简介 Spark是一个开源的计算框架平台,使用该平台,数据分析程序可自动分发到集群中的不同机器中,以解决大规模数据快速计算的问题,同时它还向上提供一个优雅的编程范式,使得 ...