Skip to content

Commit 43a7395

Browse files
fix: fixed removeAllEdges
1 parent a7a0fc4 commit 43a7395

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

  • packages/react-native-audio-api/common/cpp/audioapi/core/utils/graph

packages/react-native-audio-api/common/cpp/audioapi/core/utils/graph/HostGraph.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class HostGraph {
4141
};
4242

4343
/// Size of the Disposer payload (= sizeof(std::shared_ptr<T[]>)).
44-
static constexpr size_t kDisposerPayloadSize = 16;
44+
static constexpr size_t kDisposerPayloadSize = 24;
4545

4646
/// Event that modifies AudioGraph to keep it consistent with HostGraph.
4747
/// The second argument is the Disposer used to offload buffer deallocation.
@@ -217,8 +217,9 @@ inline auto HostGraph::addEdge(Node *from, Node *to) -> Res {
217217
}
218218

219219
for (Node *out : from->outputs) {
220-
if (out == to)
220+
if (out == to) {
221221
return Res::Err(ResultError::EDGE_ALREADY_EXISTS);
222+
}
222223
}
223224

224225
if (hasPath(to, from)) {
@@ -267,24 +268,25 @@ inline auto HostGraph::removeAllEdges(Node *from) -> Res {
267268
return Res::Err(ResultError::NODE_NOT_FOUND);
268269
}
269270

270-
auto pairs = std::make_shared<std::vector<std::pair<std::uint32_t, std::uint32_t>>>();
271-
pairs->reserve(from->outputs.size());
271+
auto pairs = std::vector<std::pair<std::uint32_t, std::uint32_t>>();
272+
pairs.reserve(from->outputs.size());
272273

273274
for (Node *to : from->outputs) {
274275
auto itIn = std::find(to->inputs.begin(), to->inputs.end(), from);
275276
if (itIn != to->inputs.end()) {
276277
to->inputs.erase(itIn);
277278
}
278279
edgeCount_--;
279-
pairs->emplace_back(from->handle->index, to->handle->index);
280+
pairs.emplace_back(from->handle->index, to->handle->index);
280281
}
281282
from->outputs.clear();
282283

283-
return Res::Ok([pairs = std::move(pairs)](AudioGraph &graph, auto &) {
284-
for (auto &[fromIdx, toIdx] : *pairs) {
284+
return Res::Ok([pairs = std::move(pairs)](AudioGraph &graph, auto &disposer) mutable {
285+
for (const auto &[fromIdx, toIdx] : pairs) {
285286
graph.pool().remove(graph[toIdx].input_head, fromIdx);
286287
}
287288
graph.markDirty();
289+
disposer.dispose(std::move(pairs));
288290
});
289291
}
290292

0 commit comments

Comments
 (0)