@@ -690,21 +690,22 @@ SDObject *WrappedVulkan::InsertEventNodes(BakedCmdBufferInfo &cmdBufInfo)
690690 // or clone the subdraw to create more that we can then patch.
691691 if (countExtraNodes != 0 )
692692 {
693+ size_t baseCommandStart = i + 1 ;
693694 // everything afterwards is adjusted. Now see if we need to remove the subdraw or clone it
694695 if (indirectCount == 0 )
695696 {
696697 // Copy the flags and resource usage from the subdraw to the indirect action (push marker)
697- n.action .flags |= eventNodes[i + 1 ].action .flags ;
698+ n.action .flags |= eventNodes[baseCommandStart ].action .flags ;
698699 // This ordering matches the existing ordering in the ActionNode resource usage
699- n.resourceUsage .swap (eventNodes[i + 1 ].resourceUsage );
700- n.resourceUsage .append (eventNodes[i + 1 ].resourceUsage );
700+ n.resourceUsage .swap (eventNodes[baseCommandStart ].resourceUsage );
701+ n.resourceUsage .append (eventNodes[baseCommandStart ].resourceUsage );
701702
702703 // i is the pushmarker, which we leave. i+1 is the subdraw
703- eventNodes.erase (i + 1 );
704+ eventNodes.erase (baseCommandStart );
704705 }
705706 else if (countExtraNodes > 0 )
706707 {
707- uint32_t chunkIndex = eventNodes[i + 1 ].event .chunkIndex ;
708+ uint32_t chunkIndex = eventNodes[baseCommandStart ].event .chunkIndex ;
708709 // duplicate the fake structured data chunk N times
709710 SDChunk *chunk = m_StructuredFile->chunks [chunkIndex];
710711
@@ -714,17 +715,19 @@ SDObject *WrappedVulkan::InsertEventNodes(BakedCmdBufferInfo &cmdBufInfo)
714715 m_StructuredFile->chunks .push_back (chunk->Duplicate ());
715716
716717 // now copy the subdraw so we're not inserting into the array from itself
717- VulkanEventNode node = eventNodes[i + 1 ];
718+ VulkanEventNode node = eventNodes[baseCommandStart];
719+ size_t baseCommandEnd = baseCommandStart + 1 ;
718720
719721 eventNodes.resize (eventNodes.size () + countExtraNodes);
720- for (size_t e = eventNodes.size () - 1 ; e > i + 1 + countExtraNodes; e--)
722+ // Shift the nodes after the placeholder forwards by countExtraNodes
723+ for (size_t e = eventNodes.size () - 1 ; e >= baseCommandEnd + countExtraNodes; e--)
721724 eventNodes[e] = std::move (eventNodes[e - countExtraNodes]);
722725
723726 // then insert enough duplicates
724727 for (int32_t e = 0 ; e < countExtraNodes; e++)
725728 {
726729 node.event .chunkIndex = baseAddedChunk + e;
727- eventNodes[i + 2 + e] = node;
730+ eventNodes[baseCommandEnd + e] = node;
728731 }
729732 }
730733 }
0 commit comments