From 36d348dba62a281e03338a1d05b4d352d89536a2 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 2 Jun 2012 03:12:14 +0000 Subject: [PATCH] - Don't record pointers to OptionValues outside of the OptionValues table, so that they can be redefined. SVN r3675 (trunk) --- src/menu/joystickmenu.cpp | 17 ++++++++---- src/menu/menudef.cpp | 4 +-- src/menu/optionmenuitems.h | 56 ++++++++++++++++++-------------------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/menu/joystickmenu.cpp b/src/menu/joystickmenu.cpp index 27bd150f8..19f87e158 100644 --- a/src/menu/joystickmenu.cpp +++ b/src/menu/joystickmenu.cpp @@ -169,12 +169,16 @@ public: int GetSelection() { double f = SELECTED_JOYSTICK->GetAxisMap(mAxis); - // Map from joystick axis to menu selection. - for(unsigned i=0;imValues.Size(); i++) + FOptionValues **opt = OptionValues.CheckKey(mValues); + if (opt != NULL && *opt != NULL) { - if (fabs(f - mValues->mValues[i].Value) < FLT_EPSILON) + // Map from joystick axis to menu selection. + for(unsigned i = 0; i < (*opt)->mValues.Size(); i++) { - return i; + if (fabs(f - (*opt)->mValues[i].Value) < FLT_EPSILON) + { + return i; + } } } return -1; @@ -182,14 +186,15 @@ public: void SetSelection(int selection) { + FOptionValues **opt = OptionValues.CheckKey(mValues); // Map from menu selection to joystick axis. - if ((unsigned)selection >= mValues->mValues.Size()) + if (opt == NULL || *opt == NULL || (unsigned)selection >= (*opt)->mValues.Size()) { selection = JOYAXIS_None; } else { - selection = (int)mValues->mValues[selection].Value; + selection = (int)(*opt)->mValues[selection].Value; } SELECTED_JOYSTICK->SetAxisMap(mAxis, (EJoyAxis)selection); } diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index 5e15a2f55..57d7751f7 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -509,7 +509,7 @@ static void ParseOptionValue(FScanner &sc) FOptionValues **pOld = OptionValues.CheckKey(optname); if (pOld != NULL && *pOld != NULL) { - sc.ScriptError("Redefinition of option value set '%s'", optname.GetChars()); + delete *pOld; } OptionValues[optname] = val; } @@ -542,7 +542,7 @@ static void ParseOptionString(FScanner &sc) FOptionValues **pOld = OptionValues.CheckKey(optname); if (pOld != NULL && *pOld != NULL) { - sc.ScriptError("Redefinition of option value set '%s'", optname.GetChars()); + delete *pOld; } OptionValues[optname] = val; } diff --git a/src/menu/optionmenuitems.h b/src/menu/optionmenuitems.h index 8aab6f9c6..461af0478 100644 --- a/src/menu/optionmenuitems.h +++ b/src/menu/optionmenuitems.h @@ -134,7 +134,7 @@ class FOptionMenuItemOptionBase : public FOptionMenuItem { protected: // action is a CVAR - FOptionValues *mValues; + FName mValues; // Entry in OptionValues table FBaseCVar *mGrayCheck; int mCenter; public: @@ -147,15 +147,7 @@ public: FOptionMenuItemOptionBase(const char *label, const char *menu, const char *values, const char *graycheck, int center) : FOptionMenuItem(label, menu) { - FOptionValues **opt = OptionValues.CheckKey(values); - if (opt != NULL) - { - mValues = *opt; - } - else - { - mValues = NULL; - } + mValues = values; mGrayCheck = (FBoolCVar*)FindCVar(graycheck, NULL); mCenter = center; } @@ -165,11 +157,11 @@ public: if (i == OP_VALUES) { FOptionValues **opt = OptionValues.CheckKey(newtext); - if (opt != NULL) + mValues = newtext; + if (opt != NULL && *opt != NULL) { - mValues = *opt; int s = GetSelection(); - if (s >= (int)mValues->mValues.Size()) s = 0; + if (s >= (int)(*opt)->mValues.Size()) s = 0; SetSelection(s); // readjust the CVAR if its value is outside the range now return true; } @@ -197,13 +189,14 @@ public: int overlay = grayed? MAKEARGB(96,48,0,0) : 0; const char *text; int Selection = GetSelection(); - if (Selection < 0) + FOptionValues **opt = OptionValues.CheckKey(mValues); + if (Selection < 0 || opt == NULL || *opt == NULL) { text = "Unknown"; } else { - text = mValues->mValues[Selection].Text; + text = (*opt)->mValues[Selection].Text; } screen->DrawText (SmallFont, OptionSettings.mFontColorValue, indent + CURSORSPACE, y, text, DTA_CleanNoMove_1, true, DTA_ColorOverlay, overlay, TAG_DONE); @@ -213,17 +206,18 @@ public: //============================================================================= bool MenuEvent (int mkey, bool fromcontroller) { - if (mValues->mValues.Size() > 0) + FOptionValues **opt = OptionValues.CheckKey(mValues); + if (opt != NULL && *opt != NULL && (*opt)->mValues.Size() > 0) { int Selection = GetSelection(); if (mkey == MKEY_Left) { if (Selection == -1) Selection = 0; - else if (--Selection < 0) Selection = mValues->mValues.Size()-1; + else if (--Selection < 0) Selection = (*opt)->mValues.Size()-1; } else if (mkey == MKEY_Right || mkey == MKEY_Enter) { - if (++Selection >= (int)mValues->mValues.Size()) Selection = 0; + if (++Selection >= (int)(*opt)->mValues.Size()) Selection = 0; } else { @@ -263,14 +257,15 @@ public: int GetSelection() { int Selection = -1; - if (mValues != NULL && mCVar != NULL && mValues->mValues.Size() > 0) + FOptionValues **opt = OptionValues.CheckKey(mValues); + if (opt != NULL && *opt != NULL && mCVar != NULL && (*opt)->mValues.Size() > 0) { - if (mValues->mValues[0].TextValue.IsEmpty()) + if ((*opt)->mValues[0].TextValue.IsEmpty()) { UCVarValue cv = mCVar->GetGenericRep(CVAR_Float); - for(unsigned i=0;imValues.Size(); i++) - { - if (fabs(cv.Float - mValues->mValues[i].Value) < FLT_EPSILON) + for(unsigned i = 0; i < (*opt)->mValues.Size(); i++) + { + if (fabs(cv.Float - (*opt)->mValues[i].Value) < FLT_EPSILON) { Selection = i; break; @@ -280,9 +275,9 @@ public: else { UCVarValue cv = mCVar->GetGenericRep(CVAR_String); - for(unsigned i=0;imValues.Size(); i++) + for(unsigned i = 0; i < (*opt)->mValues.Size(); i++) { - if (mValues->mValues[i].TextValue.CompareNoCase(cv.String) == 0) + if ((*opt)->mValues[i].TextValue.CompareNoCase(cv.String) == 0) { Selection = i; break; @@ -296,18 +291,19 @@ public: void SetSelection(int Selection) { UCVarValue value; - if (mValues != NULL && mCVar != NULL && mValues->mValues.Size() > 0) + FOptionValues **opt = OptionValues.CheckKey(mValues); + if (opt != NULL && *opt != NULL && mCVar != NULL && (*opt)->mValues.Size() > 0) { - if (mValues->mValues[0].TextValue.IsEmpty()) + if ((*opt)->mValues[0].TextValue.IsEmpty()) { - value.Float = (float)mValues->mValues[Selection].Value; + value.Float = (float)(*opt)->mValues[Selection].Value; mCVar->SetGenericRep (value, CVAR_Float); } else { - value.String = mValues->mValues[Selection].TextValue.LockBuffer(); + value.String = (*opt)->mValues[Selection].TextValue.LockBuffer(); mCVar->SetGenericRep (value, CVAR_String); - mValues->mValues[Selection].TextValue.UnlockBuffer(); + (*opt)->mValues[Selection].TextValue.UnlockBuffer(); } } }