VABList数据写入增加越界检查

This commit is contained in:
hyzboy 2025-06-06 00:22:45 +08:00
parent f762d77b1d
commit 427340132f
2 changed files with 39 additions and 9 deletions

View File

@ -38,16 +38,31 @@ public:
return write_count>=vab_count;
}
void Add(const VkBuffer buf,const VkDeviceSize offset)
bool Add(const VkBuffer buf,const VkDeviceSize offset)
{
if(IsFull())
{
//如果在这里出现错误一般是材质的VertexInput与实现要使用的不匹配。很多时候是由于引擎自动添加的VertexInput但材质里没有。
//比较典型的情况是创建材质时设置了不需要L2W,但实际又进行了传递
return(false); //列表已满
}
vab_list[write_count]=buf;
vab_offset[write_count]=offset;
++write_count;
return(true);
}
void Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
bool Add(const VkBuffer *buf,const VkDeviceSize *offset,const uint32_t count)
{
if(!buf||!offset||!count)
return(false);
if(write_count+count>vab_count)
return(false); //列表已满
hgl_cpy(vab_list +write_count,buf, count);
if(offset)
@ -56,6 +71,7 @@ public:
hgl_set<VkDeviceSize>(vab_offset+write_count,VkDeviceSize(0),count);
write_count+=count;
return(true);
}
};//class VABList
VK_NAMESPACE_END

View File

@ -346,13 +346,21 @@ bool MaterialRenderList::BindVAB(const MeshDataBuffer *pdb,const uint ri_index)
//Basic组它所有的VAB信息均来自于Primitive由vid参数传递进来
{
vab_list->Add(pdb->vab_list,
pdb->vab_offset,
pdb->vab_count);
if(!vab_list->Add(pdb->vab_list,pdb->vab_offset,pdb->vab_count))
{
//这个情况很严重哦!
return(false);
}
}
if(assign_buffer) //L2W/MI分发组
vab_list->Add(assign_buffer->GetVAB(),0);//ASSIGN_VAB_STRIDE_BYTES*ri_index);
if (assign_buffer) //L2W/MI分发组
{
if(!vab_list->Add(assign_buffer->GetVAB(),0))//ASSIGN_VAB_STRIDE_BYTES*ri_index);
{
//一般出现这个情况是因为材质中没有配置需要L2W
return(false);
}
}
//if(!vab_list.IsFull()) //Joint组暂未支持
//{
@ -405,7 +413,7 @@ void MaterialRenderList::ProcIndirectRender()
indirect_draw_count=0;
}
void MaterialRenderList::Render(RenderItem *ri)
bool MaterialRenderList::Render(RenderItem *ri)
{
if(!last_data_buffer||*(ri->pdb)!=*last_data_buffer) //换buf了
{
@ -415,7 +423,11 @@ void MaterialRenderList::Render(RenderItem *ri)
last_data_buffer=ri->pdb;
last_render_data=nullptr;
BindVAB(ri->pdb,ri->first_instance);
if(!BindVAB(ri->pdb,ri->first_instance))
{
//这个问题很严重哦
return(false);
}
if(ri->pdb->ibo)
cmd_buf->BindIBO(ri->pdb->ibo);
@ -432,6 +444,8 @@ void MaterialRenderList::Render(RenderItem *ri)
{
cmd_buf->Draw(ri->pdb,ri->prd,ri->instance_count,ri->first_instance);
}
return(true);
}
void MaterialRenderList::Render(RenderCmdBuffer *rcb)