Cleanup of IGUIObject classes

- Explicitly delete move constructor and move assignment operator to
  avoid risk of memory leaks
- Remove unused class and typo
- Use same invocation of ScriptInterface as elsewhere
This commit is contained in:
Itms
2025-08-10 22:25:40 +02:00
committed by Nicolas Auvray
parent 74bbdca25f
commit cea708ac91
4 changed files with 9 additions and 8 deletions
+4 -5
View File
@@ -31,9 +31,8 @@
#include "ps/CLogger.h"
#include "ps/Profiler2.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptExceptions.h"
#include "scriptinterface/ScriptExtraHeaders.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/ScriptInterface.h"
#include "soundmanager/ISoundManager.h"
#include <algorithm>
@@ -84,7 +83,7 @@ IGUIObject::IGUIObject(CGUI& pGUI)
IGUIObject::~IGUIObject()
{
if (!m_ScriptHandlers.empty())
JS_RemoveExtraGCRootsTracer(ScriptRequest(m_pGUI.GetScriptInterface()).cx, Trace, this);
JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetGeneralJSContext(), Trace, this);
// m_Children is deleted along all other GUI Objects in the CGUI destructor
}
@@ -357,7 +356,7 @@ void IGUIObject::RegisterScriptHandler(const CStr& eventName, const CStr& Code,
void IGUIObject::SetScriptHandler(const CStr& eventName, JS::HandleObject Function)
{
if (m_ScriptHandlers.empty())
JS_AddExtraGCRootsTracer(ScriptRequest(m_pGUI.GetScriptInterface()).cx, Trace, this);
JS_AddExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetGeneralJSContext(), Trace, this);
m_ScriptHandlers[eventName] = JS::Heap<JSObject*>(Function);
@@ -375,7 +374,7 @@ void IGUIObject::UnsetScriptHandler(const CStr& eventName)
m_ScriptHandlers.erase(it);
if (m_ScriptHandlers.empty())
JS_RemoveExtraGCRootsTracer(ScriptRequest(m_pGUI.GetScriptInterface()).cx, Trace, this);
JS_RemoveExtraGCRootsTracer(m_pGUI.GetScriptInterface()->GetGeneralJSContext(), Trace, this);
std::unordered_map<CStr, std::vector<IGUIObject*>>::iterator it2 = m_pGUI.m_EventObjects.find(eventName);
if (it2 == m_pGUI.m_EventObjects.end())
+5
View File
@@ -75,6 +75,11 @@ class IGUIObject
public:
NONCOPYABLE(IGUIObject);
// IGUIObjects must not be moved in memory: SpiderMonkey keeps a pointer to
// them in order to trace script handlers during GCs (see Set/UnsetScriptHandlers())
IGUIObject(IGUIObject&&) = delete;
IGUIObject& operator=(IGUIObject&&) = delete;
IGUIObject(CGUI& pGUI);
virtual ~IGUIObject();
-2
View File
@@ -94,8 +94,6 @@ CInput::CInput(CGUI& pGUI)
m_PlaceholderText(this, "placeholder_text"),
m_PlaceholderColor(this, "placeholder_color")
{
;
auto bar = std::make_unique<CGUIScrollBarVertical>(pGUI);
bar->SetRightAligned(true);
AddScrollBar(std::move(bar));
-1
View File
@@ -32,7 +32,6 @@ class CGUI;
class CScrollPanel : public IGUIPanel, public IGUIScrollBarOwner
{
GUI_OBJECT(CScrollPanel)
mutable std::vector<IGUIObject*> m_ModifiedChildren; // To store the modified vector
public:
CScrollPanel(CGUI& pGUI);