@@ -121,7 +121,10 @@ void InstancedBuffer::merge(scene::SubModel *subModel, uint32_t passIdx, gfx::Sh
121121 );
122122}
123123
124- void InstancedBuffer::_appendInstance (InstancedItem& instance, Uint8Array buffer, gfx::Shader* shader, gfx::DescriptorSet* descriptorSet) {
124+ void InstancedBuffer::_appendInstance (InstancedItem &instance,
125+ Uint8Array& buffer,
126+ gfx::Shader *shader,
127+ gfx::DescriptorSet *descriptorSet) {
125128 if (instance.drawInfo .instanceCount >= instance.capacity ) { // resize buffers
126129 instance.capacity = std::min (instance.capacity << 1 , MAX_CAPACITY );
127130 const auto newSize = instance.stride * instance.capacity ;
@@ -145,7 +148,7 @@ void InstancedBuffer::_appendInstance(InstancedItem& instance, Uint8Array buffer
145148void InstancedBuffer::_createInstance (const ccstd::string &key,
146149 gfx::InputAssembler *sourceIA,
147150 const ccstd::vector<gfx::Attribute> &attributes,
148- Uint8Array buffer,
151+ Uint8Array & buffer,
149152 uint32_t stride,
150153 gfx::Shader *shader,
151154 gfx::DescriptorSet *descriptorSet,
@@ -204,9 +207,10 @@ void InstancedBuffer::uploadBuffers(gfx::CommandBuffer *cmdBuff) const {
204207 // bytes from `instance.data` would read out of bounds and crash. Clamp to the smaller
205208 // of the two to avoid reading past the end of `instance.data`.
206209 const uint32_t dataCapacity = instance.capacity * instance.stride ;
207- const uint32_t copySize = std::min (instance.vb ->getSize (), dataCapacity);
208- CC_ASSERT (copySize == instance.vb ->getSize ());
209- cmdBuff->updateBuffer (instance.vb , instance.data , copySize);
210+ const uint32_t validSize = instance.drawInfo .instanceCount * instance.stride ;
211+ CC_ASSERT (validSize <= instance.vb ->getSize ());
212+ CC_ASSERT (validSize <= dataCapacity);
213+ cmdBuff->updateBuffer (instance.vb , instance.data , validSize);
210214 instance.ia ->setInstanceCount (instance.drawInfo .instanceCount );
211215 }
212216}
0 commit comments