Fix ADPCM encoder buffer overflow causing silent AWC build failure#10
Open
Prompt-Coder wants to merge 1 commit intoRenewed-Scripts:mainfrom
Open
Fix ADPCM encoder buffer overflow causing silent AWC build failure#10Prompt-Coder wants to merge 1 commit intoRenewed-Scripts:mainfrom
Prompt-Coder wants to merge 1 commit intoRenewed-Scripts:mainfrom
Conversation
CodeWalker's ADPCMCodec.EncodeADPCM sizes its output buffer as data.Length / 4 and processes input in 8192-byte blocks. When the PCM data chunk is not a multiple of 8192 bytes the final partial block writes a 4-byte block header past the end of the output buffer, raising IndexOutOfRangeException. That exception is swallowed by AwcFile.ReadXml, leaving DataChunk.Data null; BuildPeakChunks then NREs on data.Length, showing the user "Object reference not set to an instance of an object". Fix 1 (WavConverter): pad every converted WAV's PCM data chunk to the next 8192-byte boundary with zero (silent) bytes before passing it to CodeWalker. Recompute audio.Samples from the actual padded byte count so the XML <Samples> value stays accurate. Fix 2 (AWCBuilder): replace the empty catch(Exception) with one that logs the full exception type, message, and stack trace to awc_build_error.log and surfaces the error text in the failure dialog. Previously all build errors were silently swallowed, forcing users to "manually build" with no indication of what went wrong.
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.
Problem
Building an AWC resource with certain audio files (especially 48 kHz sources or larger banks) silently fails — Audiotool retries 5 times then shows:
No error details. The real exception is swallowed by the empty
catch (Exception)inBuildAWC.Root cause
CodeWalker.Core'sADPCMCodec.EncodeADPCMallocates its output buffer asdata.Length / 4and processes input in 8192-byte blocks. When the PCMdatachunk is not a multiple of 8192 bytes, the final partial block writes a 4-byte block header past the end of the output buffer →IndexOutOfRangeException.AwcFile.ReadXmlcatches that exception silently, leavingDataChunk.Datanull.BuildPeakChunksthen NREs ondata.Length, which is what the user sees as "Object reference not set to an instance of an object".Fix
WavConverter.cs— after each WAV is written, pad the PCMdatachunk to the next 8192-byte boundary with zero (silent) bytes before CodeWalker reads it. Also recomputesaudio.Samplesfrom the actual post-padding byte count so the generated<Samples>value in the XML stays accurate.AWCBuilder.cs— replace the emptycatch (Exception)with one that logs the full exception type, message, and stack trace toawc_build_error.logand shows the error text in the failure dialog. Silently swallowing the exception made every AWC build error impossible to diagnose.Testing
Verified against a 25-stream, 48 kHz audio bank that previously failed on every build attempt. After the fix it builds cleanly on the first try.