Bug fix for segmentation fault when deleting all cheats. Instead of using callback based iterator function to delete each cheat, added a new function that will just cleanly delete all cheats without the need for a callback.

This commit is contained in:
mjbudd77 2021-05-02 20:49:08 -04:00
parent b97bf287b2
commit 974d2aefba
3 changed files with 43 additions and 14 deletions

View File

@ -886,7 +886,8 @@ void FCEU_CheatSetByte(uint32 A, uint8 V)
}
// disable all cheats
int FCEU_DisableAllCheats(){
int FCEU_DisableAllCheats(void)
{
int count = 0;
struct CHEATF *next = cheats;
while(next)
@ -902,6 +903,28 @@ int FCEU_DisableAllCheats(){
return count;
}
// delete all cheats
int FCEU_DeleteAllCheats(void)
{
struct CHEATF *cur = cheats;
struct CHEATF *next = NULL;
while (cur)
{
next = cur->next;
if ( cur->name )
{
free(cur->name);
}
free(cur);
cur = next;
}
cheats = cheatsl = 0;
savecheats = 1;
RebuildSubCheats();
return 0;
}
int FCEUI_FindCheatMapByte(uint16 address)
{
return cheatMap[address / 8] >> (address % 8) & 1;

View File

@ -30,7 +30,8 @@ extern int savecheats;
extern int globalCheatDisabled;
extern int disableAutoLSCheats;
int FCEU_DisableAllCheats();
int FCEU_DisableAllCheats(void);
int FCEU_DeleteAllCheats(void);
typedef struct {
uint16 addr;

View File

@ -2846,20 +2846,23 @@ void QHexEdit::contextMenuEvent(QContextMenuEvent *event)
subMenu = menu.addMenu(tr("&Freeze/Unfreeze Address"));
act = new QAction(tr("&Toggle State"), &menu);
act->setShortcut( QKeySequence(tr("Ctrl+L")));
subMenu->addAction(act);
connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamToggle(void)) );
if ( frzRamAddrValid( addr ) )
{
act = new QAction(tr("&Toggle State"), &menu);
act->setShortcut( QKeySequence(tr("Ctrl+L")));
subMenu->addAction(act);
connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamToggle(void)) );
act = new QAction(tr("&Freeze"), &menu);
subMenu->addAction(act);
connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamSet(void)) );
act = new QAction(tr("&Freeze"), &menu);
subMenu->addAction(act);
connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamSet(void)) );
act = new QAction(tr("&Unfreeze"), &menu);
subMenu->addAction(act);
connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamUnset(void)) );
act = new QAction(tr("&Unfreeze"), &menu);
subMenu->addAction(act);
connect( act, SIGNAL(triggered(void)), this, SLOT(frzRamUnset(void)) );
subMenu->addSeparator();
subMenu->addSeparator();
}
act = new QAction(tr("Unfreeze &All"), &menu);
subMenu->addAction(act);
@ -3016,6 +3019,8 @@ int QHexEdit::FreezeRam( const char *name, uint32_t a, uint8_t v, int c, int s,
if ( s )
{
FCEUI_DelCheat( frzIdx );
frzRamAddr = -1;
return 0;
}
break;
default:
@ -3101,7 +3106,7 @@ void QHexEdit::frzRamUnsetAll(void)
return;
}
fceuWrapperLock();
FCEUI_ListCheats( RamFreezeCB, this);
FCEU_DeleteAllCheats();
updateCheatDialog();
fceuWrapperUnLock();
}