Made Event::ErrorInternal const

Fixed ProcessEvent() not handling exceptions
This commit is contained in:
smallmodel 2023-08-19 21:00:04 +02:00
parent a83a76da95
commit 5b82cc4f11
No known key found for this signature in database
GPG key ID: A96F163ED4891440
4 changed files with 49 additions and 62 deletions

View file

@ -57,7 +57,7 @@ void ConsoleEvent::SetConsoleEdict(gentity_t* edict)
GetConsoleEdict
=======================
*/
gentity_t* ConsoleEvent::GetConsoleEdict(void)
gentity_t* ConsoleEvent::GetConsoleEdict(void) const
{
if (m_consoleedict)
return m_consoleedict;
@ -70,7 +70,7 @@ gentity_t* ConsoleEvent::GetConsoleEdict(void)
ErrorInternal
=======================
*/
void ConsoleEvent::ErrorInternal(Listener* l, str text)
void ConsoleEvent::ErrorInternal(Listener* l, str text) const
{
gentity_t* edict = GetConsoleEdict();
str eventname = getName();

View file

@ -19,9 +19,9 @@ public:
ConsoleEvent(str name) : Event(name) { m_consoleedict = NULL; }
void SetConsoleEdict(gentity_t* edict);
gentity_t* GetConsoleEdict(void);
gentity_t* GetConsoleEdict(void) const;
void ErrorInternal(Listener* l, str text) override;
void ErrorInternal(Listener* l, str text) const override;
};
extern MEM_BlockAlloc<ConsoleEvent> ConsoleEvent_allocator;

View file

@ -1862,7 +1862,7 @@ Event::Event()
ErrorInternal
=======================
*/
void Event::ErrorInternal( Listener *l, str text )
void Event::ErrorInternal( Listener *l, str text ) const
{
str classname;
str eventname;
@ -2533,7 +2533,7 @@ EventDef *Event::getInfo()
getName
=======================
*/
str& Event::getName()
str& Event::getName() const
{
return GetEventName( eventnum );
}
@ -2926,48 +2926,18 @@ ProcessEvent
*/
bool Listener::ProcessEvent( Event *ev )
{
ClassDef *c = classinfo();
ResponseDef<Class> *responses = NULL;
Response response = NULL;
if( !ev->eventnum )
{
#ifdef _DEBUG
EVENT_DPrintf( "^~^~^ Failed execution of event '%s' for class '%s'\n", ev->name.c_str(), c->classname );
#else
EVENT_DPrintf( "^~^~^ Failed execution of event for class '%s'\n", c->classname );
#endif
delete ev;
return false;
}
responses = c->responseLookup[ ev->eventnum ];
if( responses == NULL )
{
delete ev;
return true;
}
response = responses->response;
try
{
if( response )
{
( this->*response )( ev );
}
}
catch( ScriptException& exc )
{
ev->ErrorInternal( this, exc.string );
EVENT_DPrintf( "%s\n", exc.string.c_str() );
}
delete ev;
return true;
try
{
return ProcessScriptEvent(ev);
}
catch (ScriptException& exc)
{
ev->ErrorInternal(this, exc.string);
EVENT_DPrintf("%s\n", exc.string.c_str());
// at this point the event didn't get deleted
delete ev;
return false;
}
}
/*
@ -2977,7 +2947,35 @@ ProcessEvent
*/
bool Listener::ProcessEvent( Event &ev )
{
return ProcessScriptEvent( ev );
try
{
return ProcessScriptEvent(ev);
}
catch (ScriptException& exc)
{
ev.ErrorInternal(this, exc.string);
EVENT_DPrintf("%s\n", exc.string.c_str());
return false;
}
}
/*
=======================
ProcessEvent
=======================
*/
bool Listener::ProcessEvent( const Event &ev )
{
try
{
return ProcessScriptEvent(Event(ev));
}
catch (ScriptException& exc)
{
ev.ErrorInternal(this, exc.string);
EVENT_DPrintf("%s\n", exc.string.c_str());
return false;
}
}
/*
@ -3033,17 +3031,6 @@ ScriptVariable& Listener::ProcessEventReturn( Event *ev )
return m_Return;
}
/*
=======================
ProcessEvent
=======================
*/
bool Listener::ProcessEvent( const Event &ev )
{
Event *event = new Event( ev );
return ProcessEvent( event );
}
/*
=======================
ProcessScriptEvent

View file

@ -291,7 +291,7 @@ public:
static int compareEvents( const void *arg1, const void *arg2 );
static void SortEventList( Container< int > *sortedList );
virtual void ErrorInternal( Listener *l, str text );
virtual void ErrorInternal( Listener *l, str text ) const;
static unsigned int FindEventNum( str s );
static unsigned int FindNormalEventNum( const_str s );
@ -340,7 +340,7 @@ public:
EventDef *getInfo();
#endif
str& getName();
str& getName() const;
void AddContainer( Container< SafePtr< Listener > > *container );
void AddEntity( Entity * ent );