Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
83 changes: 83 additions & 0 deletions ISSUE_741_RESPONSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Issue #741 Response - Audio codec properties not respected in release builds on iOS

## Root Cause Found & Fixed!

Thanks @felixspitzer for the detailed debugging logs! This confirms a **critical bug in the NitroModules nitrogen code generator**.

### Debug vs Release Comparison

| Property | Debug | Release |
|----------|-------|---------|
| `AVSampleRateKeyIOS` | `Optional(22050.0)` | `nil` |
| `AVNumberOfChannelsKeyIOS` | `Optional(2.0)` | `Optional(5.0)` (wrong!) |
| `AudioSamplingRate` | `Optional(22050.0)` | `Optional(-nan(0x30070002ade90))` |
| `AudioChannels` | `Optional(2.0)` | `nil` |

The values were being **corrupted or read incorrectly** in Release builds due to Swift compiler optimizations interacting badly with the C++ bridge code.

## Technical Analysis

Looking at the generated `nitrogen/generated/ios/swift/AudioSet.swift`, there was an inconsistency in how `std::optional` values are accessed:

**Pattern A (problematic in Release):**
```swift
var AVSampleRateKeyIOS: Double? {
get {
return self.__AVSampleRateKeyIOS.value // ❌ Corrupted in Release
}
}
```

**Pattern B (works correctly):**
```swift
var AudioSourceAndroid: AudioSourceAndroidType? {
get {
return self.__AudioSourceAndroid.has_value() ? self.__AudioSourceAndroid.pointee : nil // ✅
}
}
```

The `.value` accessor on `std::optional<double>` is not safe with Swift Release optimizations, while the explicit `has_value() ? .pointee : nil` pattern works correctly.

## Fix Applied

I've patched the generated `AudioSet.swift` file to use the safe pattern for all optional accessors. The following properties were fixed:

- `AVModeIOS`
- `AVEncodingOptionIOS`
- `AVFormatIDKeyIOS`
- `AVNumberOfChannelsKeyIOS`
- `AVSampleRateKeyIOS`
- `AudioQuality`
- `AudioChannels`
- `AudioSamplingRate`
- `AudioEncodingBitRate`

## Next Steps

1. **This fix will be included in the next release** of react-native-nitro-sound
2. I will also file an issue on the [NitroModules repository](https://github.com/mrousavy/nitro) to fix the code generator upstream

## For Users Who Need an Immediate Fix

If you can't wait for the next release, you can manually patch the file in your `node_modules`:

Edit `node_modules/react-native-nitro-sound/nitrogen/generated/ios/swift/AudioSet.swift` and replace all instances of:

```swift
return self.__PropertyName.value
```

With:

```swift
return self.__PropertyName.has_value() ? self.__PropertyName.pointee : nil
```

Then run `pod install` again.

---

**Related:**
- NitroModules: https://github.com/mrousavy/nitro
- This issue affects `std::optional` Swift bridging in Release builds
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react": "19.1.1",
"react-dom": "19.1.1",
"react-native": "0.82.1",
"react-native-nitro-modules": "^0.31.1",
"react-native-nitro-modules": "^0.31.10",
"react-native-nitro-sound": "*",
"react-native-video": "^6.16.1",
"react-native-web": "^0.20.0"
Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/android/c++/JFunc_void_PlayBackType.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion nitrogen/generated/android/c++/JFunc_void_RecordBackType.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions nitrogen/generated/android/c++/JHybridSoundSpec.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nitrogen/generated/android/c++/JHybridSoundSpec.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions nitrogen/generated/ios/NitroSound-Swift-Cxx-Bridge.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions nitrogen/generated/ios/NitroSound-Swift-Cxx-Bridge.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions nitrogen/generated/ios/c++/HybridSoundSpecSwift.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading