From 6f648c564e39a418ca128e85e15ef85547c20f94 Mon Sep 17 00:00:00 2001 From: Zhou Zhenglong Date: Mon, 8 Jul 2024 17:20:27 +0800 Subject: [PATCH 1/2] fix dangling reference --- .../pipeline/custom/NativeResourceGraph.cpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp index 5e2d67160b6..cb04fbc3652 100644 --- a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -228,23 +228,23 @@ 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); visitObject( vertID, resg, - [&](const ManagedResource& resource) { + [](const ManagedResource& resource) { // to be removed }, - [&](ManagedBuffer& buffer) { + [this, device, vertID](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) { + [this, device, vertID, &resg](ManagedTexture& texture) { + const auto& desc = get(ResourceGraph::DescTag{}, *this, vertID); if (!texture.checkResource(desc)) { auto info = getTextureInfo(desc); texture.texture = device->createTexture(info); @@ -262,25 +262,25 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { CC_ENSURES(texture.texture); texture.fenceValue = nextFenceValue; }, - [&](const PersistentBuffer& buffer) { + [](const PersistentBuffer& buffer) { CC_EXPECTS(buffer.buffer); std::ignore = buffer; }, - [&](const PersistentTexture& texture) { + [](const PersistentTexture& texture) { CC_EXPECTS(texture.texture); std::ignore = texture; }, - [&](const IntrusivePtr& fb) { + [](const IntrusivePtr& fb) { // deprecated CC_EXPECTS(false); CC_EXPECTS(fb); std::ignore = fb; }, - [&](const RenderSwapchain& window) { + [](const RenderSwapchain& window) { CC_EXPECTS(window.swapchain || window.renderWindow); std::ignore = window; }, - [&](const FormatView& view) { // NOLINT(misc-no-recursion) + [this, device, vertID, &resg](const FormatView& view) { // NOLINT(misc-no-recursion) std::ignore = view; auto parentID = parent(vertID, resg); CC_EXPECTS(parentID != resg.null_vertex()); @@ -292,9 +292,10 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { CC_ENSURES(!resg.isTextureView(parentID)); mount(device, parentID); }, - [&](SubresourceView& view) { // NOLINT(misc-no-recursion) + [this, device, vertID, &resg](SubresourceView& view) { // NOLINT(misc-no-recursion) 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); } From dc231efdc9aa118fe5429dfe85972d505b2c4a18 Mon Sep 17 00:00:00 2001 From: Zhou Zhenglong Date: Mon, 8 Jul 2024 17:25:12 +0800 Subject: [PATCH 2/2] simplify fix --- .../pipeline/custom/NativeResourceGraph.cpp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp index cb04fbc3652..1f17b4fd094 100644 --- a/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeResourceGraph.cpp @@ -228,13 +228,12 @@ void recreateTextureView( // NOLINTNEXTLINE(misc-no-recursion) void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { - auto& resg = *this; visitObject( - vertID, resg, - [](const ManagedResource& resource) { + vertID, *this, + [&](const ManagedResource& resource) { // to be removed }, - [this, device, vertID](ManagedBuffer& buffer) { + [&](ManagedBuffer& buffer) { if (!buffer.buffer) { const auto& desc = get(ResourceGraph::DescTag{}, *this, vertID); auto info = getBufferInfo(desc); @@ -243,7 +242,7 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { CC_ENSURES(buffer.buffer); buffer.fenceValue = nextFenceValue; }, - [this, device, vertID, &resg](ManagedTexture& texture) { + [&](ManagedTexture& texture) { const auto& desc = get(ResourceGraph::DescTag{}, *this, vertID); if (!texture.checkResource(desc)) { auto info = getTextureInfo(desc); @@ -253,7 +252,7 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { const auto childID = child(e, *this); auto* view = get_if(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); } @@ -262,26 +261,27 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { CC_ENSURES(texture.texture); texture.fenceValue = nextFenceValue; }, - [](const PersistentBuffer& buffer) { + [&](const PersistentBuffer& buffer) { CC_EXPECTS(buffer.buffer); std::ignore = buffer; }, - [](const PersistentTexture& texture) { + [&](const PersistentTexture& texture) { CC_EXPECTS(texture.texture); std::ignore = texture; }, - [](const IntrusivePtr& fb) { + [&](const IntrusivePtr& fb) { // deprecated CC_EXPECTS(false); CC_EXPECTS(fb); std::ignore = fb; }, - [](const RenderSwapchain& window) { + [&](const RenderSwapchain& window) { CC_EXPECTS(window.swapchain || window.renderWindow); std::ignore = window; }, - [this, device, vertID, &resg](const FormatView& view) { // NOLINT(misc-no-recursion) + [&](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)) { @@ -292,7 +292,8 @@ void ResourceGraph::mount(gfx::Device* device, vertex_descriptor vertID) { CC_ENSURES(!resg.isTextureView(parentID)); mount(device, parentID); }, - [this, device, vertID, &resg](SubresourceView& view) { // NOLINT(misc-no-recursion) + [&](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);