add notifyInsDeletion

prevent invalid memory access when deleting instruments
This commit is contained in:
tildearrow 2022-01-13 19:36:02 -05:00
parent 0545775de6
commit 91e8ff01cf
18 changed files with 61 additions and 0 deletions

View File

@ -215,3 +215,9 @@ void DivMacroInt::init(DivInstrument* which) {
arpMode=true;
}
}
void DivMacroInt::notifyInsDeletion(DivInstrument* which) {
if (ins==which) {
init(NULL);
}
}

View File

@ -17,6 +17,7 @@ class DivMacroInt {
bool arpMode;
void next();
void init(DivInstrument* which);
void notifyInsDeletion(DivInstrument* which);
DivMacroInt():
ins(NULL),
volPos(0),

View File

@ -331,6 +331,12 @@ bool DivPlatformAY8910::keyOffAffectsArp(int ch) {
return true;
}
void DivPlatformAY8910::notifyInsDeletion(void* ins) {
for (int i=0; i<3; i++) {
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
}
}
int DivPlatformAY8910::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
skipRegisterWrites=false;

View File

@ -59,6 +59,7 @@ class DivPlatformAY8910: public DivDispatch {
void muteChannel(int ch, bool mute);
bool isStereo();
bool keyOffAffectsArp(int ch);
void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void quit();
};

View File

@ -311,6 +311,12 @@ void DivPlatformC64::forceIns() {
updateFilter();
}
void DivPlatformC64::notifyInsDeletion(void* ins) {
for (int i=0; i<3; i++) {
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
}
}
void DivPlatformC64::reset() {
for (int i=0; i<3; i++) {
chan[i]=DivPlatformC64::Channel();

View File

@ -61,6 +61,7 @@ class DivPlatformC64: public DivDispatch {
void tick();
void muteChannel(int ch, bool mute);
void setPAL(bool pal);
void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void setChipModel(bool is6581);
void quit();

View File

@ -317,6 +317,12 @@ bool DivPlatformGB::isStereo() {
return true;
}
void DivPlatformGB::notifyInsDeletion(void* ins) {
for (int i=0; i<4; i++) {
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
}
}
int DivPlatformGB::init(DivEngine* p, int channels, int sugRate, bool pal) {
for (int i=0; i<4; i++) {
isMuted[i]=false;

View File

@ -45,6 +45,7 @@ class DivPlatformGB: public DivDispatch {
void tick();
void muteChannel(int ch, bool mute);
bool isStereo();
void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void quit();
~DivPlatformGB();

View File

@ -423,6 +423,10 @@ bool DivPlatformGenesis::keyOffAffectsPorta(int ch) {
return (ch>5);
}
void DivPlatformGenesis::notifyInsDeletion(void* ins) {
psg.notifyInsDeletion(ins);
}
void DivPlatformGenesis::setPAL(bool pal) {
if (pal) {
rate=211125;

View File

@ -60,6 +60,7 @@ class DivPlatformGenesis: public DivDispatch {
bool keyOffAffectsArp(int ch);
bool keyOffAffectsPorta(int ch);
void setPAL(bool pal);
void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void quit();
~DivPlatformGenesis();

View File

@ -324,6 +324,12 @@ void DivPlatformNES::setPAL(bool pal) {
}
}
void DivPlatformNES::notifyInsDeletion(void* ins) {
for (int i=0; i<5; i++) {
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
}
}
int DivPlatformNES::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
skipRegisterWrites=false;

View File

@ -50,6 +50,7 @@ class DivPlatformNES: public DivDispatch {
void muteChannel(int ch, bool mute);
bool keyOffAffectsArp(int ch);
void setPAL(bool pal);
void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void quit();
~DivPlatformNES();

View File

@ -313,6 +313,12 @@ bool DivPlatformPCE::keyOffAffectsArp(int ch) {
return true;
}
void DivPlatformPCE::notifyInsDeletion(void* ins) {
for (int i=0; i<6; i++) {
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
}
}
void DivPlatformPCE::setPAL(bool pal) {
if (pal) { // technically there is no PAL PC Engine but oh well...
rate=1773448/6;

View File

@ -65,6 +65,7 @@ class DivPlatformPCE: public DivDispatch {
bool isStereo();
bool keyOffAffectsArp(int ch);
void setPAL(bool pal);
void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void quit();
~DivPlatformPCE();

View File

@ -193,6 +193,12 @@ int DivPlatformSMS::getPortaFloor(int ch) {
return 12;
}
void DivPlatformSMS::notifyInsDeletion(void* ins) {
for (int i=0; i<4; i++) {
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
}
}
void DivPlatformSMS::setPAL(bool pal) {
if (pal) {
rate=221681;

View File

@ -42,6 +42,7 @@ class DivPlatformSMS: public DivDispatch {
bool keyOffAffectsPorta(int ch);
int getPortaFloor(int ch);
void setPAL(bool pal);
void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void quit();
~DivPlatformSMS();

View File

@ -589,6 +589,12 @@ bool DivPlatformYM2610::keyOffAffectsArp(int ch) {
return (ch>3);
}
void DivPlatformYM2610::notifyInsDeletion(void* ins) {
for (int i=4; i<7; i++) {
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
}
}
int DivPlatformYM2610::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
skipRegisterWrites=false;

View File

@ -71,6 +71,7 @@ class DivPlatformYM2610: public DivDispatch {
void muteChannel(int ch, bool mute);
bool isStereo();
bool keyOffAffectsArp(int ch);
void notifyInsDeletion(void* ins);
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void quit();
~DivPlatformYM2610();