Fix critical crash bugs in AAC encoder plugin#9
Closed
paterkleomenis wants to merge 1 commit into
Closed
Conversation
- Fix ring buffer overflow: m_ringBufferFill was incrementing beyond bounds - Add NULL checks for all FFmpeg allocations (av_frame_alloc, av_packet_alloc, etc.) - Add initialization validation in DoProcess to prevent crashes - Add bounds checking in ring buffer helper functions - Remove duplicate initialization code in DoInit - Fix build system to use g++ instead of clang++ - Add comprehensive documentation in CRASH_FIXES.md These fixes prevent DaVinci Resolve from crashing when loading the plugin.
paterkleomenis
commented
Nov 24, 2025
paterkleomenis
left a comment
Contributor
Author
There was a problem hiding this comment.
this should work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix critical crash bugs in AAC encoder plugin
Summary
This PR fixes critical bugs that were causing DaVinci Resolve to crash when loading the AAC audio encoder plugin.
Problem
The plugin was crashing DaVinci Resolve on load due to several memory safety issues and unhandled error conditions in the FFmpeg integration code.
Issues Fixed
1. Ring Buffer Overflow Bug (Critical)
m_ringBufferFillwas incrementing beyondm_frameSizebounds, causing memory corruptionaudio_encoder.cpp-AddPCMToRingBuffer()functionBefore:
After:
2. Missing NULL Checks for FFmpeg Allocations
audio_encoder.cpp-DoInit()andDoProcess()functionsavcodec_alloc_context3()- codec context allocationav_frame_alloc()- frame allocationav_packet_alloc()- packet allocationav_channel_layout_copy()- channel layout copyav_frame_get_buffer()- frame buffer allocationAll failures now properly clean up allocated resources and return
errFailwith error logging.3. Initialization Validation
audio_encoder.cpp-DoProcess()function4. Memory Safety in Ring Buffer Helpers
audio_encoder.cpp-GetFrameFromRingBuffer()andAddPCMToRingBuffer()5. Duplicate Initialization Code
frame_sizeandptswere duplicated inDoInit()6. Build System Compatibility
clang++with clang-specific flags, but g++ was more commonly availableclang++tog++in.mk.defs-stdlib=libstdc++flag fromMakefileChanges Made
Modified Files:
audio_encoder.cpp- Fixed ring buffer logic, added NULL checks and validation.mk.defs- Changed compiler from clang++ to g++Makefile- Removed clang-specific flagsNew Files:
CRASH_FIXES.md- Comprehensive documentation of all fixesTesting
✅ Build Test: Plugin compiles successfully without errors
✅ Load Test: Plugin loads in DaVinci Resolve without crashing
✅ Export Test: Successfully exports video with AAC audio encoding
✅ Sample Rate Test: Tested with 44100 Hz and 48000 Hz
✅ Bit Depth Test: Tested with 16-bit and 24-bit audio
Compatibility
Additional Notes
All memory management has been improved with proper cleanup on failure paths. Error messages have been enhanced to help diagnose issues if they occur. The plugin should now be stable for production use.
Related Issues
Fixes the crash issue reported where DaVinci Resolve would close immediately when the plugin was added.