Skip to content

Commit 8a5a0ed

Browse files
fix ai CI error
1 parent 20d13dd commit 8a5a0ed

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

native/cocos/renderer/pipeline/InstancedBuffer.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
145148
void 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
}

native/cocos/renderer/pipeline/InstancedBuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ class InstancedBuffer : public RefCounted {
7979

8080
private:
8181
void _appendInstance(InstancedItem &instance,
82-
Uint8Array buffer,
82+
Uint8Array &buffer,
8383
gfx::Shader *shader,
8484
gfx::DescriptorSet *descriptorSet);
8585
void _createInstance(const ccstd::string &key,
8686
gfx::InputAssembler *sourceIA,
8787
const ccstd::vector<gfx::Attribute> &attributes,
88-
Uint8Array buffer,
88+
Uint8Array &buffer,
8989
uint32_t stride,
9090
gfx::Shader *shader,
9191
gfx::DescriptorSet *descriptorSet,

0 commit comments

Comments
 (0)