Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Channel negotiation drops buffer swaps when several graph changes land in one render quantum

Aperta
#1,332 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@mdydek ci sta già lavorando.

Dal 14/10/2026.

  • #1343 di @mdydek — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, react-native

Direzione di ricerca

Start in common/cpp/audioapi/core/utils/graph/HostGraph.cpp, especially buildNegotiatedBufferIfNeeded, then inspect HostGraph::Node and initialization in addNode. Add the described reproductions to common/cpp/test/src/graph/GraphTest.cpp and run the graph tests; done means the batched channel changes leave the destination at the expected channel count.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Description

While a context is rendering, HostGraph can leave a node with the wrong channel count. Stereo
content then plays mono, and a StereoPannerNode or PannerNode placed after it no longer pans.
On a device it is intermittent: it depends on whether an audio callback runs between the JS calls.

buildNegotiatedBufferIfNeeded (common/cpp/audioapi/core/utils/graph/HostGraph.cpp) runs on the
JS thread. It skips the swap when the node's live buffer already has the computed channel count.
Swaps queued earlier in the same batch have not reached the audio thread yet. So when a node goes
2 → 1 → 2 within one batch, the second negotiation sees the live 2 and queues nothing, and the
queued swap to 1 is applied last. Offline before startRendering(), or in a suspended context, the
producer drains its own events, so the live buffer is current and the bug does not show.

A common JS pattern that should hit it (inferred from reading the code; the C++ test below is the
verified reproduction):

// In one JS task, while the context is running:
const source = ctx.createBufferSource();
source.connect(gain);         // no buffer yet: 1 output channel, gain -> 1 is queued
source.buffer = stereoBuffer; // 2 output channels: gain's live buffer still has 2, nothing is queued
source.start();               // gain stays mono

Another one: a mono source and a StereoPannerNode connected to the same gain in one task. This is
what Howler's sound.stereo(pan) does: the gain stays mono and the panned output collapses to the
center.

Steps to reproduce

Add this to common/cpp/test/src/graph/GraphTest.cpp. There is no processEvents() between the two
changes, as on a running context where both apply in the same render quantum:

TEST_F(GraphTest, ComputedNumberOfChannels_MaxMode_BatchedChangesBackToLiveWidth) {
  auto *mono = addChannelCountNode(*graph, {.channelCount = 1, .mode = ChannelCountMode::EXPLICIT});
  auto *stereo = addChannelCountNode(*graph, {.channelCount = 2, .mode = ChannelCountMode::EXPLICIT});
  auto *dest = addChannelCountNode(*graph, {.channelCount = 2, .mode = ChannelCountMode::MAX});
  graph->processEvents();

  ASSERT_TRUE(graph->addEdge(mono, dest).is_ok());
  ASSERT_TRUE(graph->addEdge(stereo, dest).is_ok());
  graph->processEvents();

  EXPECT_EQ(channelsOf(dest), 2u); // fails on main: 1
}

The same happens with addEdge(mono, dest) followed by removeEdge(mono, dest) (expected 2, got
1), and with a source whose output channel number changes from 1 to 2 after addEdge, followed by
renegotiateNodeChannels (expected 2, got 1). All three fail on main (b8491e1).

Proposed fix

Record on HostGraph::Node the channel count of the last swap queued for the audio thread,
initialized in addNode (AudioGraph does not know the node yet, so reading its buffer there is
safe), and compare against it instead of the live buffer. With this change the three cases pass, and
so do the smoke suite (460 tests) and the graph category (659 tests). I can open a PR with the fix
and the tests.

Snack or a link to a repository

no React Native app. We embed the C++ engine in a custom iOS runtime; the reproduction is the GraphTest case above.

React Native Audio API version

1.0.0

React Native version

0.75.3

Platforms

iOS

JavaScript runtime

Hermes

Workflow

None

Architecture

None

Build type

None

Device

Real device

Device model

No response

Acknowledgements

Yes

Lingua principale
C++
Stelle
848
Fork
94
Merge medio
4g 20m
PR unite (30g)
31

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di software-mansion/react-native-audio-api

Tutte le issue di software-mansion/react-native-audio-api

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.