Skip to content

Commit

Permalink
Re-allocation using samples caused Crash; Fix
Browse files Browse the repository at this point in the history
Re-allocating larger wavetables in some very specific size
cases mis-allocated the size required for the silence which
was appended. This left memory mis-aligned causing an immediate
crash on Windows in some cases. Fix by adding the silence pad to the
required size for a given set of tables.

Closes surge-synthesizer#1087
  • Loading branch information
baconpaul committed Sep 1, 2019
1 parent 9d98bed commit c67f48a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/common/dsp/Wavetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ size_t RequiredWTSize(int TableSize, int TableCount)
{
int Size = 0;

TableCount += 3; // for sample padding. Should match the "3" in the AppendSilence block below.
while (TableSize > 0)
{
Size += TableCount * (TableSize + FIRoffsetI16 + FIRipolI16_N);
Expand Down Expand Up @@ -167,7 +168,7 @@ bool Wavetable::BuildWT(void* wdata, wt_header& wh, bool AppendSilence)

if (AppendSilence)
{
n_tables += 3;
n_tables += 3; // this "3" should match the "3" in RequiredWTSize
}

#if WINDOWS
Expand Down

0 comments on commit c67f48a

Please sign in to comment.