commit 65d057d8e1ab2aeb57c050824b6823b8435c0475
parent 50ed2bdf957de8388be0cadc00daea6fa9fe13e1
Author: fundamental <mark.d.mccurry@gmail.com>
Date: Thu, 14 Mar 2013 21:13:12 -0400
Fixes possible plugin segfault issue
This issue appears to be a regression pointed out by falktx.
Improper ordering of two statements resulted in possible stack smashing leading
to 'interesting' bugs.
Memory previously statically allocated is now allocated per instance of Master
to prevent collisions.
Diffstat:
4 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -303,9 +303,6 @@ add_subdirectory(Synth)
add_subdirectory(Effects)
add_subdirectory(Params)
add_subdirectory(DSP)
-if(CompileTests)
- add_subdirectory(Tests)
-endif(CompileTests)
add_subdirectory(Nio)
add_library(zynaddsubfx_core STATIC
@@ -323,6 +320,10 @@ target_link_libraries(zynaddsubfx_core
${OS_LIBRARIES}
pthread)
+if(CompileTests)
+ add_subdirectory(Tests)
+endif(CompileTests)
+
message(STATUS "using link directories: ${AUDIO_LIBRARY_DIRS} ${ZLIB_LIBRARY_DIRS} ${FFTW_LIBRARY_DIRS} ${MXML_LIBRARY_DIRS} ${FLTK_LIBRARY_DIRS}")
diff --git a/src/Misc/Master.cpp b/src/Misc/Master.cpp
@@ -50,6 +50,10 @@ static Master* masterInstance = NULL;
Master::Master()
{
swaplr = 0;
+ off = 0;
+ smps = 0;
+ bufl = new float[synth->buffersize];
+ bufr = new float[synth->buffersize];
pthread_mutex_init(&mutex, NULL);
pthread_mutex_init(&vumutex, NULL);
@@ -482,11 +486,6 @@ void Master::GetAudioOutSamples(size_t nsamples,
float *outl,
float *outr)
{
- static float *bufl = new float[synth->buffersize],
- *bufr = new float[synth->buffersize];
- static off_t off = 0;
- static size_t smps = 0;
-
off_t out_off = 0;
//Fail when resampling rather than doing a poor job
@@ -505,9 +504,8 @@ void Master::GetAudioOutSamples(size_t nsamples,
//generate samples
AudioOut(bufl, bufr);
off = 0;
- smps = synth->buffersize;
-
out_off += smps;
+ smps = synth->buffersize;
}
else { //use some samples
memcpy(outl + out_off, bufl + off, sizeof(float) * nsamples);
@@ -521,6 +519,9 @@ void Master::GetAudioOutSamples(size_t nsamples,
Master::~Master()
{
+ delete []bufl;
+ delete []bufr;
+
for(int npart = 0; npart < NUM_MIDI_PARTS; ++npart)
delete part[npart];
for(int nefx = 0; nefx < NUM_INS_EFX; ++nefx)
diff --git a/src/Misc/Master.h b/src/Misc/Master.h
@@ -171,6 +171,12 @@ class Master
float sysefxvol[NUM_SYS_EFX][NUM_MIDI_PARTS];
float sysefxsend[NUM_SYS_EFX][NUM_SYS_EFX];
int keyshift;
+
+ //information relevent to generating plugin audio samples
+ float *bufl;
+ float *bufr;
+ off_t off;
+ size_t smps;
};
#endif
diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt
@@ -12,6 +12,7 @@ CXXTEST_ADD_TEST(SUBnoteTest SubNoteTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/SubNote
CXXTEST_ADD_TEST(OscilGenTest OscilGenTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/OscilGenTest.h)
CXXTEST_ADD_TEST(RandTest RandTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/RandTest.h)
CXXTEST_ADD_TEST(PADnoteTest PadNoteTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PadNoteTest.h)
+CXXTEST_ADD_TEST(PluginTest PluginTest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PluginTest.h)
#Extra libraries added to make test and full compilation use the same library
#links for quirky compilers
@@ -26,5 +27,7 @@ target_link_libraries(MicrotonalTest ${test_lib})
target_link_libraries(OscilGenTest ${test_lib})
target_link_libraries(XMLwrapperTest ${test_lib})
target_link_libraries(RandTest ${test_lib})
-target_link_libraries(PADnoteTest ${test_lib})
+target_link_libraries(PADnoteTest ${test_lib})
+target_link_libraries(PluginTest zynaddsubfx_core zynaddsubfx_nio
+ ${OS_LIBRARIES} ${AUDIO_LIBRARIES})