@@ -19,10 +19,6 @@ PluginObject::PluginObject(std::string m_name, ContextKinds m_kind)
19
19
20
20
PluginObject::~PluginObject ()
21
21
{
22
- if (eventFunctionPtr)
23
- {
24
- delete eventFunctionPtr;
25
- }
26
22
}
27
23
28
24
void PluginObject::RegisterEventHandlerJSON (EValue* functionPtr)
@@ -57,9 +53,6 @@ void PluginObject::UnregisterEventHandling(std::string eventName)
57
53
58
54
EventResult PluginObject::TriggerEvent (std::string invokedBy, std::string eventName, std::vector<std::any> eventPayload, ClassData* eventObject)
59
55
{
60
- if (GetPluginState () == PluginState_t::Stopped && eventName != " OnPluginStart" && eventName != " OnAllPluginsLoaded" )
61
- return EventResult::Continue;
62
-
63
56
if (!eventFunctionPtr)
64
57
return EventResult::Continue;
65
58
@@ -73,11 +66,14 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN
73
66
EventResult response = EventResult::Continue;
74
67
try
75
68
{
76
- if (!eventObject) {
77
- ClassData tmpObject ({ { " plugin_name" , invokedBy } }, " Event" , ctx);
78
- eventObject = &tmpObject;
69
+ ClassData* localObj = eventObject;
70
+ bool created = false ;
71
+ if (!localObj) {
72
+ localObj = new ClassData ({ { " plugin_name" , invokedBy } }, " Event" , ctx);
73
+ created = true ;
79
74
}
80
- auto value = (*eventFunctionPtr)(eventObject, eventName, eventPayload);
75
+
76
+ auto value = (*eventFunctionPtr)(localObj, eventName, eventPayload);
81
77
if (value.isNumber ())
82
78
{
83
79
int result = value.cast <int >();
@@ -86,6 +82,7 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN
86
82
else
87
83
response = (EventResult)result;
88
84
}
85
+ if (created) delete localObj;
89
86
}
90
87
catch (EException& e)
91
88
{
@@ -101,9 +98,6 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN
101
98
102
99
EventResult PluginObject::TriggerEventJSON (std::string invokedBy, std::string eventName, std::string eventPayload, ClassData* eventObject)
103
100
{
104
- if (GetPluginState () == PluginState_t::Stopped && eventName != " OnPluginStart" && eventName != " OnAllPluginsLoaded" )
105
- return EventResult::Continue;
106
-
107
101
if (!eventFunctionPtr)
108
102
return EventResult::Continue;
109
103
@@ -117,11 +111,14 @@ EventResult PluginObject::TriggerEventJSON(std::string invokedBy, std::string ev
117
111
EventResult response = EventResult::Continue;
118
112
try
119
113
{
120
- if (!eventObject) {
121
- ClassData tmpObject ({ { " plugin_name" , invokedBy } }, " Event" , ctx);
122
- eventObject = &tmpObject;
114
+ ClassData* localObj = eventObject;
115
+ bool created = false ;
116
+ if (!localObj) {
117
+ localObj = new ClassData ({ { " plugin_name" , invokedBy } }, " Event" , ctx);
118
+ created = true ;
123
119
}
124
- auto value = (*eventFunctionPtrJSON)(eventObject, eventName, eventPayload);
120
+
121
+ auto value = (*eventFunctionPtrJSON)(localObj, eventName, eventPayload);
125
122
if (value.isNumber ())
126
123
{
127
124
int result = value.cast <int >();
@@ -130,6 +127,7 @@ EventResult PluginObject::TriggerEventJSON(std::string invokedBy, std::string ev
130
127
else
131
128
response = (EventResult)result;
132
129
}
130
+ if (created) delete localObj;
133
131
}
134
132
catch (EException& e)
135
133
{
@@ -304,6 +302,17 @@ void PluginObject::DestroyScriptingEnvironment()
304
302
g_commandsManager.UnregisterCommand (command);
305
303
306
304
eventHandlers.clear ();
305
+
306
+ if (eventFunctionPtr) {
307
+ delete eventFunctionPtr;
308
+ eventFunctionPtr = nullptr ;
309
+ }
310
+
311
+ if (eventFunctionPtrJSON) {
312
+ delete eventFunctionPtrJSON;
313
+ eventFunctionPtrJSON = nullptr ;
314
+ }
315
+
307
316
delete ctx;
308
317
}
309
318
0 commit comments