- added extra validation for status bar classes

Print a message when status bar class defined in GAMEINFO is missing or when it's not derived from BaseStatusBar
Validate internal status bar classes for basic consistency in Debug configuration
This commit is contained in:
alexey.lysiuk 2018-06-29 13:47:06 +03:00
parent 0703030be3
commit 907ce777a3
2 changed files with 35 additions and 11 deletions

View file

@ -1567,7 +1567,11 @@ DBaseStatusBar *CreateCustomStatusBar(int scriptno)
auto script = SBarInfoScript[scriptno];
if (script == nullptr) return nullptr;
auto sbar = (DBaseStatusBar*)PClass::FindClass("SBarInfoWrapper")->CreateNew();
PClass *sbarclass = PClass::FindClass("SBarInfoWrapper");
assert(sbarclass != nullptr);
assert(sbarclass->IsDescendantOf(RUNTIME_CLASS(DBaseStatusBar)));
auto sbar = (DBaseStatusBar*)sbarclass->CreateNew();
auto core = new DSBarInfo(sbar, script);
sbar->PointerVar<DSBarInfo>("core") = core;
sbar->SetSize(script->height, script->_resW, script->_resH);

View file

@ -247,6 +247,31 @@ static void CreateBaseStatusBar()
StatusBar->SetSize(0);
}
static void CreateGameInfoStatusBar(bool &shouldWarn)
{
auto cls = PClass::FindClass(gameinfo.statusbarclass);
if (cls == nullptr)
{
if (shouldWarn)
{
Printf(TEXTCOLOR_RED "Unknown status bar class \"%s\"\n", gameinfo.statusbarclass.GetChars());
shouldWarn = false;
}
}
else
{
if (cls->IsDescendantOf(RUNTIME_CLASS(DBaseStatusBar)))
{
StatusBar = (DBaseStatusBar *)cls->CreateNew();
}
else if (shouldWarn)
{
Printf(TEXTCOLOR_RED "Status bar class \"%s\" is not derived from BaseStatusBar\n", gameinfo.statusbarclass.GetChars());
shouldWarn = false;
}
}
}
void ST_CreateStatusBar(bool bTitleLevel)
{
if (StatusBar != NULL)
@ -255,6 +280,8 @@ void ST_CreateStatusBar(bool bTitleLevel)
StatusBar = NULL;
}
bool shouldWarn = true;
if (bTitleLevel)
{
CreateBaseStatusBar();
@ -268,11 +295,7 @@ void ST_CreateStatusBar(bool bTitleLevel)
int sbarinfofile = Wads.GetLumpFile(sbarinfolump);
if (gameinfo.statusbarclassfile >= gameinfo.statusbarfile && gameinfo.statusbarclassfile >= sbarinfofile)
{
auto cls = PClass::FindClass(gameinfo.statusbarclass);
if (cls != nullptr)
{
StatusBar = (DBaseStatusBar *)cls->CreateNew();
}
CreateGameInfoStatusBar(shouldWarn);
}
}
if (StatusBar == nullptr && SBarInfoScript[SCRIPT_CUSTOM] != nullptr)
@ -291,11 +314,7 @@ void ST_CreateStatusBar(bool bTitleLevel)
// SBARINFO failed so try the current statusbarclass again.
if (StatusBar == nullptr)
{
auto cls = PClass::FindClass(gameinfo.statusbarclass);
if (cls != nullptr)
{
StatusBar = (DBaseStatusBar *)cls->CreateNew();
}
CreateGameInfoStatusBar(shouldWarn);
}
}
if (StatusBar == nullptr)
@ -311,6 +330,7 @@ void ST_CreateStatusBar(bool bTitleLevel)
auto cls = PClass::FindClass(defname);
if (cls != nullptr)
{
assert(cls->IsDescendantOf(RUNTIME_CLASS(DBaseStatusBar)));
StatusBar = (DBaseStatusBar *)cls->CreateNew();
}
}