From bcff44c0a36b5c53eb781dfbe5e0be1e6803bee0 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 12 Jan 2018 09:13:41 +0100 Subject: [PATCH] Fixes: delete unused creaed objects whenn errors occurs or plugin in unloaded. --- src/Makefile | 6 +++--- src/dexed.cpp | 23 ++++++++++++++++++----- src/msfa/controllers.h | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index 86ead0e..6a17374 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,8 +1,8 @@ BUNDLE=dexed.lv2 TARGET=dexed.so -#DEBUG=1 -#FILETRACE=1 +DEBUG=1 +FILETRACE=1 INSTALL_DIR=/zynthian/zynthian-plugins/lv2 INSTALL_MYPLUGINS_DIR=/zynthian/zynthian-my-plugins/lv2 @@ -88,7 +88,7 @@ $(BUNDLE): manifest.ttl Dexed.ttl modgui.ttl presets.ttl dexed.so dexed.so: $(OBJ) dexed.o $(CXX) dexed.o $(OBJ) $(LDFLAGS) -o dexed.so -dexed.o: Makefile dexed.cpp dexed.h dexed_ttl.h +dexed.o: Makefile dexed.cpp dexed.h dexed_ttl.h msfa/controllers.h $(CXX) $(CXXFLAGS) -Wall -c dexed.cpp trace.o: Makefile trace.c trace.h diff --git a/src/dexed.cpp b/src/dexed.cpp index 110b96d..a105ee2 100644 --- a/src/dexed.cpp +++ b/src/dexed.cpp @@ -49,24 +49,30 @@ Dexed::Dexed(double rate) : lvtk::Synth(p_n_ports, p_midi_in) Env::init_sr(rate); fx.init(rate); - if((engineMkI=new EngineMkI)==NULL) + if(!(engineMkI=new EngineMkI)) { TRACE("Cannot not create engine EngineMkI"); exit(400); } - if((engineOpl=new EngineOpl)==NULL) + if(!(engineOpl=new EngineOpl)) { + if(engineMkI) + delete(engineMkI); TRACE("Cannot not create engine EngineOpl"); exit(401); } - if((engineMsfa=new FmCore)==NULL) + if(!(engineMsfa=new FmCore)) { + if(engineMkI) + delete(engineMkI); + if(engineOpl) + delete(engineOpl); TRACE("Cannot create engine FmCore"); exit(402); } for(i=0; i(p_n_ports, p_midi_in) bufsize_=256; - if((outbuf_=new float[bufsize_])==NULL) + if(!(outbuf_=new float[bufsize_])) { TRACE("Cannot create outbuf_ buffer"); exit(404); @@ -144,6 +150,13 @@ Dexed::~Dexed() voices[note].live = false; } + if(engineMsfa) + delete(engineMkI); + if(engineOpl) + delete(engineMkI); + if(engineMkI) + delete(engineMkI); + TRACE("Bye"); TRACE("--------------------------------------------------------------------------------"); } diff --git a/src/msfa/controllers.h b/src/msfa/controllers.h index 9a399ee..3aca269 100755 --- a/src/msfa/controllers.h +++ b/src/msfa/controllers.h @@ -65,6 +65,7 @@ class Controllers { void applyMod(int cc, FmMod &mod) { float range = 0.01 * mod.range; uint8_t total = cc * range; + TRACE("amp[%d]|pitch[%d]|eg[%d] %d",mod.amp,mod.pitch,mod.eg,total); if(mod.amp) amp_mod = max(amp_mod, total);