From f48af606df36ea9e9f7d970faf80a87595fdb69a Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 31 Mar 2017 12:53:28 +0300 Subject: [PATCH] Fixed creation of BaseStatusBar No more access to memory ouside of class instance Minimized amount of copy-pasted code https://mantis.zdoom.org/view.php?id=511 --- src/g_statusbar/sbarinfo.cpp | 5 ----- src/g_statusbar/shared_sbar.cpp | 33 +++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index a5fd45d28..a46911217 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1546,11 +1546,6 @@ DBaseStatusBar *CreateCustomStatusBar(int scriptno) I_FatalError("Tried to create a status bar with no script!"); auto sbar = (DBaseStatusBar*)PClass::FindClass("SBarInfoWrapper")->CreateNew(); - IFVIRTUALPTR(sbar, DBaseStatusBar, Init) - { - VMValue params[] = { sbar }; - GlobalVMStack.Call(func, params, 1, nullptr, 0); - } auto core = new DSBarInfo(sbar, script); sbar->PointerVar("core") = core; sbar->SetSize(script->height, script->_resW, script->_resH); diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 160a0d499..6a3bdfd55 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -251,6 +251,17 @@ void ST_Clear() // //--------------------------------------------------------------------------- +static void CreateBaseStatusBar() +{ + assert(nullptr == StatusBar); + + PClass* const statusBarClass = PClass::FindClass("BaseStatusBar"); + assert(nullptr != statusBarClass); + + StatusBar = static_cast(statusBarClass->CreateNew()); + StatusBar->SetSize(0); +} + void ST_CreateStatusBar(bool bTitleLevel) { if (StatusBar != NULL) @@ -261,8 +272,7 @@ void ST_CreateStatusBar(bool bTitleLevel) if (bTitleLevel) { - StatusBar = new DBaseStatusBar(); - StatusBar->SetSize(0); + CreateBaseStatusBar(); } else { @@ -277,11 +287,6 @@ void ST_CreateStatusBar(bool bTitleLevel) if (cls != nullptr) { StatusBar = (DBaseStatusBar *)cls->CreateNew(); - IFVIRTUALPTR(StatusBar, DBaseStatusBar, Init) - { - VMValue params[] = { StatusBar }; - GlobalVMStack.Call(func, params, 1, nullptr, 0); - } } } } @@ -313,18 +318,18 @@ void ST_CreateStatusBar(bool bTitleLevel) if (cls != nullptr) { StatusBar = (DBaseStatusBar *)cls->CreateNew(); - IFVIRTUALPTR(StatusBar, DBaseStatusBar, Init) - { - VMValue params[] = { StatusBar }; - GlobalVMStack.Call(func, params, 1, nullptr, 0); - } } } } if (StatusBar == nullptr) { - StatusBar = new DBaseStatusBar(); - StatusBar->SetSize(0); + CreateBaseStatusBar(); + } + + IFVIRTUALPTR(StatusBar, DBaseStatusBar, Init) + { + VMValue params[] = { StatusBar }; + GlobalVMStack.Call(func, params, 1, nullptr, 0); } GC::WriteBarrier(StatusBar);