Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Sources/ComputeCxx/Subgraph/IAGSubgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ IAGUniqueID IAGSubgraphAddObserver(IAGSubgraphRef subgraph,

void IAGSubgraphRemoveObserver(IAGSubgraphRef subgraph, IAGUniqueID observer_id) {
if (IAG::Subgraph::from_cf(subgraph) == nullptr) {
IAG::precondition_failure("accessing invalidated subgraph");
return;
}

IAG::Subgraph::from_cf(subgraph)->remove_observer(observer_id);
Expand Down
33 changes: 33 additions & 0 deletions Tests/ComputeTests/Shared/Subgraph/SubgraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,39 @@ struct SubgraphTests {

#expect(notifiedCount == 0)
}

@Test
func removeObserverAfterInvalidation() {
let graph = Graph()
let subgraph = Subgraph(graph: graph)
var notifiedCount = 0
let observerID = subgraph.addObserver {
notifiedCount += 1
}

subgraph.invalidate()
subgraph.removeObserver(observerID)

#expect(subgraph.isValid == false)
#expect(notifiedCount == 1)
}

@Test
func removeObserverDuringInvalidation() {
let graph = Graph()
let subgraph = Subgraph(graph: graph)
var notifiedCount = 0
var observerID = 0
observerID = subgraph.addObserver {
notifiedCount += 1
subgraph.removeObserver(observerID)
}

subgraph.invalidate()

#expect(subgraph.isValid == false)
#expect(notifiedCount == 1)
}
}

@Suite
Expand Down
Loading