Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dangling reference caused by vector resize #17330

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,22 @@ void recreateTextureView(

// NOLINTNEXTLINE(misc-no-recursion)
void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) {
std::ignore = device;
auto& resg = *this;
const auto& desc = get(ResourceGraph::DescTag{}, *this, vertID);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desc might be invalidated if new resource is added.

visitObject(
vertID, resg,
vertID, *this,
[&](const ManagedResource& resource) {
// to be removed
},
[&](ManagedBuffer& buffer) {
if (!buffer.buffer) {
const auto& desc = get(ResourceGraph::DescTag{}, *this, vertID);
auto info = getBufferInfo(desc);
buffer.buffer = device->createBuffer(info);
}
CC_ENSURES(buffer.buffer);
buffer.fenceValue = nextFenceValue;
},
[&](ManagedTexture& texture) {
const auto& desc = get(ResourceGraph::DescTag{}, *this, vertID);
if (!texture.checkResource(desc)) {
auto info = getTextureInfo(desc);
texture.texture = device->createTexture(info);
Expand All @@ -253,7 +252,7 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) {
const auto childID = child(e, *this);
auto* view = get_if<SubresourceView>(childID, this);
if (view) {
const auto [originView, parentID] = getOriginView(resg, childID);
const auto [originView, parentID] = getOriginView(*this, childID);
CC_ENSURES(parentID == vertID);
recreateTextureView(device, *this, originView, parentID, *view);
}
Expand Down Expand Up @@ -282,6 +281,7 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) {
},
[&](const FormatView& view) { // NOLINT(misc-no-recursion)
std::ignore = view;
auto& resg = *this;
auto parentID = parent(vertID, resg);
CC_EXPECTS(parentID != resg.null_vertex());
while (resg.isTextureView(parentID)) {
Expand All @@ -293,8 +293,10 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) {
mount(device, parentID);
},
[&](SubresourceView& view) { // NOLINT(misc-no-recursion)
auto& resg = *this;
const auto [originView, parentID] = getOriginView(resg, vertID);
mount(device, parentID); // NOLINT(misc-no-recursion)
const auto& desc = get(ResourceGraph::DescTag{}, *this, vertID);
if (!isTextureEqual(view.textureView, desc)) {
recreateTextureView(device, *this, originView, parentID, view);
}
Expand Down
Loading