diff --git a/src/command.c b/src/command.c index 292c51861..341e57ce5 100644 --- a/src/command.c +++ b/src/command.c @@ -1771,7 +1771,7 @@ void CV_AddValue(consvar_t *var, INT32 increment) newvalue = var->value - 1; do { - if(increment > 0) // Going up! + if (increment > 0) // Going up! { if (++newvalue == NUMMAPS) newvalue = -1; @@ -1785,7 +1785,7 @@ void CV_AddValue(consvar_t *var, INT32 increment) if (newvalue == oldvalue) break; // don't loop forever if there's none of a certain gametype - if(!mapheaderinfo[newvalue]) + if (newvalue >= 0 && !mapheaderinfo[newvalue]) continue; // Don't allocate the header. That just makes memory usage skyrocket. } while (!M_CanShowLevelInList(newvalue, gt)); diff --git a/src/m_menu.c b/src/m_menu.c index af63de94f..95824c7dd 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2713,6 +2713,10 @@ static void M_PrepareLevelSelect(void) // boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) { + // invalid mapnum + if (mapnum < -1) + return false; + // Random map! if (mapnum == -1) return (gamestate != GS_TIMEATTACK && !modeattacking); @@ -7220,7 +7224,7 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) if (i == oldval) return; - if(!mapheaderinfo[i]) + if (i >= 0 && !mapheaderinfo[i]) continue; // Don't allocate the header. That just makes memory usage skyrocket. } while (!M_CanShowLevelInList(i, cv_newgametype.value)); @@ -7258,7 +7262,7 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) if (i == oldval) return; - if(!mapheaderinfo[i]) + if (i >= 0 && !mapheaderinfo[i]) continue; // Don't allocate the header. That just makes memory usage skyrocket. } while (!M_CanShowLevelInList(i, cv_newgametype.value));