Check for valid event on listener and print an error if the command cannot be executed

This commit is contained in:
smallmodel 2025-01-16 23:25:26 +01:00
parent 4399e2ab31
commit 539c2df378
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 18 additions and 0 deletions

View file

@ -541,6 +541,8 @@ void ScriptVM::executeCommandInternal<false>(
)
{
transferVarsToEvent(ev, fromVar, iParamCount);
checkValidEvent(ev, listener);
listener->ProcessScriptEvent(ev);
}
@ -550,6 +552,7 @@ void ScriptVM::executeCommandInternal<true>(
)
{
transferVarsToEvent(ev, fromVar, iParamCount);
checkValidEvent(ev, listener);
try {
listener->ProcessScriptEvent(ev);
@ -595,6 +598,20 @@ void ScriptVM::transferVarsToEvent(Event& ev, ScriptVariable *fromVar, op_parmNu
ev.CopyValues(fromVar, count);
}
void ScriptVM::checkValidEvent(Event& ev, Listener* listener) {
ClassDef *c = listener->classinfo();
if (!c->GetDef(&ev)) {
if (listener == m_Thread) {
ScriptError("Failed execution of command '%s'", ev.getName());
} else if (listener->isSubclassOf(SimpleEntity)) {
ScriptError("Failed execution of command '%s' for class '%s' Targetname '%s'", ev.getName(), c->classname, static_cast<SimpleEntity*>(listener)->targetname.c_str());
} else {
ScriptError("Failed execution of command '%s' for class '%s'", ev.getName(), c->classname);
}
}
}
bool ScriptVM::executeGetter(Listener *listener, op_evName_t eventName)
{
int eventNum = Event::FindGetterEventNum(eventName);