diff --git a/native/cocos/base/RefVector.h b/native/cocos/base/RefVector.h index 9fde9ae03e..e52b895ea7 100644 --- a/native/cocos/base/RefVector.h +++ b/native/cocos/base/RefVector.h @@ -220,13 +220,15 @@ public: return *this; } - T &operator[](uint32_t idx) { - return _data[idx]; - } - - const T&operator[](uint32_t idx) const { - return _data[idx]; - } + // Can not return reference, or it can use like this + // refVector[i] = val; + // Then, reference count will be wrong. In order to correct reference count, should: + // - dec refVector[i] reference count + // - add `val` reference count. + // It is hard to use, so delete it. + T &operator[](uint32_t idx) = delete; + // As non const version is disabled, disable const version too. + const T&operator[](uint32_t idx) const = delete; /** * Requests that the vector capacity be at least enough to contain n elements. diff --git a/native/cocos/core/assets/RenderingSubMesh.cpp b/native/cocos/core/assets/RenderingSubMesh.cpp index 41726ce940..6e16220196 100644 --- a/native/cocos/core/assets/RenderingSubMesh.cpp +++ b/native/cocos/core/assets/RenderingSubMesh.cpp @@ -220,7 +220,7 @@ bool RenderingSubMesh::destroy() { if (!_jointMappedBuffers.empty() && !_jointMappedBufferIndices.empty()) { for (uint32_t index : _jointMappedBufferIndices) { - _jointMappedBuffers.at(static_cast(index))->destroy(); + _jointMappedBuffers.at(index)->destroy(); } _jointMappedBuffers.clear(); _jointMappedBufferIndices.clear(); @@ -289,7 +289,7 @@ const gfx::BufferList &RenderingSubMesh::getJointMappedBuffers() { buffers.pushBack(buffer); indices.emplace_back(i); } else { - buffers.pushBack(_vertexBuffers.at(static_cast(prim.vertexBundelIndices[i]))); + buffers.pushBack(_vertexBuffers.at(prim.vertexBundelIndices[i])); } } diff --git a/native/cocos/renderer/core/ProgramLib.cpp b/native/cocos/renderer/core/ProgramLib.cpp index 7602360135..f9dc5ad924 100644 --- a/native/cocos/renderer/core/ProgramLib.cpp +++ b/native/cocos/renderer/core/ProgramLib.cpp @@ -582,7 +582,7 @@ gfx::DescriptorSetLayout *ProgramLib::getDescriptorSetLayout(gfx::Device *device info.bindings = pipeline::localDescriptorSetLayout.bindings; tmplInfo.setLayouts.replace(static_cast(pipeline::SetIndex::LOCAL), device->createDescriptorSetLayout(info)); } - return tmplInfo.setLayouts.at(isLocal ? static_cast(pipeline::SetIndex::LOCAL) : static_cast(pipeline::SetIndex::MATERIAL)); + return tmplInfo.setLayouts.at(isLocal ? static_cast(pipeline::SetIndex::LOCAL) : static_cast(pipeline::SetIndex::MATERIAL)); } ccstd::string ProgramLib::getKey(const ccstd::string &name, const MacroRecord &defines) { diff --git a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp index e92235ea65..a9ab512c03 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp @@ -48,7 +48,7 @@ void GLES2Framebuffer::doInit(const FramebufferInfo & /*info*/) { _gpuFBO->gpuColorTextures.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { - auto *colorTexture = static_cast(_colorTextures[i]); + auto *colorTexture = static_cast(_colorTextures.at(i)); _gpuFBO->gpuColorTextures[i] = colorTexture->gpuTexture(); _gpuFBO->lodLevel = colorTexture->getViewInfo().baseLevel; GLES2Device::getInstance()->framebufferHub()->connect(colorTexture->gpuTexture(), _gpuFBO); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp index e9da01cd01..e24c5f7fa1 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp @@ -48,7 +48,7 @@ void GLES3Framebuffer::doInit(const FramebufferInfo & /*info*/) { _gpuFBO->gpuColorViews.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { - auto *colorTexture = static_cast(_colorTextures[i]); + auto *colorTexture = static_cast(_colorTextures.at(i)); _gpuFBO->gpuColorViews[i] = colorTexture->gpuTextureView(); GLES3Device::getInstance()->framebufferHub()->connect(colorTexture->gpuTexture(), _gpuFBO); } diff --git a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp index 85dcde916a..b49e64b87c 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp @@ -46,7 +46,7 @@ void CCVKFramebuffer::doInit(const FramebufferInfo & /*info*/) { _gpuFBO->gpuColorViews.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { - auto *colorTex = static_cast(_colorTextures[i]); + auto *colorTex = static_cast(_colorTextures.at(i)); _gpuFBO->gpuColorViews[i] = colorTex->gpuTextureView(); CCVKDevice::getInstance()->gpuFramebufferHub()->connect(colorTex->gpuTexture(), _gpuFBO); }