Raised This Month: $32 Target: $400
 8% 

Upgrading to OB and MMS 1.8.3 causing Linux only crash on FireEvent


Post New Thread Reply   
 
Thread Tools Display Modes
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-16-2010 , 15:00   Re: Upgrading to OB and MMS 1.8.3 causing Linux only crash on FireEvent
Reply With Quote #11

Hrm, the plot thickens...

I removed the FireEvent hook but left the FFA patch in and it's running fine now, the FireEvent hook is only called for player_team which might be being called when the players are joining but I can't see why Event is not NULL yet Event->GetName() crashes...
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-16-2010 , 15:20   Re: Upgrading to OB and MMS 1.8.3 causing Linux only crash on FireEvent
Reply With Quote #12

Ok, now with ffa enabled and the FireEvent hook, if I wait until the round_starts before overriding the player_team event all is well and good... until another client connects >.<

I tried setting a bool on clientconnect and ignore the player_team event the first time it's called after clientconnect but that didn't work either... rage.

edit: Friggin worst part is this works fine on Windowz >.<
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-16-2010 , 15:29   Re: Upgrading to OB and MMS 1.8.3 causing Linux only crash on FireEvent
Reply With Quote #13

Ooooooo - checking !bDontBroadcast in the same initial check for player_team seems to be working...


Edit: bDontBroadcast is always false for this event >.<
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-17-2010 , 09:00   Re: Upgrading to OB and MMS 1.8.3 causing Linux only crash on FireEvent
Reply With Quote #14

I got to the bottom of this mess. There were two issues, one which I'm not too worried about.

The first was indeed my implementation of CSSDM's FFA - I changed it around for OB to match his CSSDM definition and managed to input the replacement strings incorrectly so god knows what it was patching with. This was causing an OnTakeDamage error which was happening if I removed the FireEvent hook.

The FireEvent hook problem was being generated by a sourcemod plugin sending a player_team event through before the client entered the game, for whatever reason the event being sent is malformed and is causing that error I reported above. I didn't bother looking to find out which one I simply disabled them all for now - it doesn't make any sense to duplicate player_team events so I'm a little surprised after finding the cause!

Anyways, all's well that ends well, running 100% since I changed those two little gems ;)
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-17-2010 , 17:48   Re: Upgrading to OB and MMS 1.8.3 causing Linux only crash on FireEvent
Reply With Quote #15

Glad that you figured it out.

Are you sure about the FireEvent problem being caused by that? I am not really convinced yet.

In the last callstack you posted, there seemed to be this series of events:

1) The server (engine) is in its normal game loop and calls IServerGameDll::GameFrame(). (frames #35 - #15)

2) This is hooked by SH, we get into the original function call, the gamedll's CServerGameDll::GameFrame (Frame #14, #13)

3) The gamedll does stuff, gets back into the engine to create a bot (Frame #12 - #6)

4) engine's CGameClient::Connect (frame #5) fires an event.

5) The FireEvent method was first hooked by SourceMod, so we get into SourceMod's hook manager.

SourceMod may have done something in its PRE-hook for the event, but we can't see that anymore in the call stack because it would have happened before the call to your PRE hook (ie. earlier).

In any case I don't see any reason to believe that the event it crashes on is being actively fired from sourcemod (ASSUMING that FireEvent would be called the moment sourcemod fires an event -- I don't know how the event management system works). It may have been modified by sourcemod in its PRE hook though (the passed object may have been modified or changed altogether with META_RETURN_*NEWPARAMS).

6) Your PRE hook gets called and crashes, apparently because the passed IGameEvent object has a weird vtable.

So my question would be:
What does SourceMod/its plugin do in its FireEvent PRE hook that makes you get an apparently corrupted object? Why doesn't it crash without your plugin if the object is corrupted?

Pretty weird.


EDIT: I have taken a look at SM's event management code. It seems that the only reason I can think of at the moment that would lead to a crash in your hook would be this branch:
Code:
   406 		if (res)
   407 		{
   408 			gameevents->FreeEvent(pEvent);
   409 			RETURN_META_VALUE(MRES_SUPERCEDE, false);
   410 		}
ie.: the plugin tells sourcemod to stop the event from being fired (MRES_SUPERCEDE) and because nobody would otherwise take care of it in that situation, sourcemod frees the event object.

You can check if this is the case by checking for META_RESULT_STATUS == MRES_SUPERCEDE.

If that should really be the problem, it's not a good situation. It would mean that when sourcemod stops an event it basically invalidates the information about the event so no other plugins can use it. I have to say that it's hard to imagine a workaround with the current design except for
0) disable the plugin stopping the event
1) make sure your plugin registers the PRE hook first
2) convince sourcemod to remember the halted event object and free it in a post hook. that way other plugins would have a chance to take a look at it in their pre hooks

In an ideal world sourcehook would have cleanup hooks where one could do such stuff, which could be guaranteed to be called after post hooks (kind of post post hooks). Though that wouldn't be ideal either because it wouldn't come for free, developers would have to actively use it even though it wouldn't cause them problems to ignore the issue.
__________________
hello, i am pm

Last edited by PM; 09-17-2010 at 18:06.
PM is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 09-18-2010 , 05:34   Re: Upgrading to OB and MMS 1.8.3 causing Linux only crash on FireEvent
Reply With Quote #16

Hi PM,

Thanks very much for looking into the issue, as always you were spot on and META_RESULT_STATUS is indeed set to MRES_SUPERCEDE in the instance of the call when it crashes. If I do a check at the start and bail out if we're already returning MRES_SUPERCEDE it runs fine. In this instance that's ok as all I want to do is SUPERCEDE the function anyway so it's job done...

I have two small questions if you have time.

The first is why are subsequent hooks being called after SourceHook received an MRES_SUPERCEDE from any function in the tree at all? It was my understanding SourceHook would stop all subsequent calls upon receipt of that return value?

The second is what do you think about PRE hooking IGameEventManager2::FreeEvent( IGameEvent *event ) ? It's a virtual in the same interface as my current hook and I can check the type of event in the FreeEvent hook and SUPERCEDE it but mark the entity as needing Freeing, and then destroy it myself when I get to the end of my own function.
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-18-2010 , 11:06   Re: Upgrading to OB and MMS 1.8.3 causing Linux only crash on FireEvent
Reply With Quote #17

Helloes,

1) All hooks are always called (pre and post). This is a design decision inherited from the original metamod for HL1. The idea is that all plugins should be somehow equal and a plugin doesn't stop working (ie. not receive a notifiaction) when another plugin SUPERCEDEs a function call. The plugins can always ask metamod/SourceHook about the last plugin's MRES (i forgot the macro name) or about the highest returned MRES (META_RESULT_STATUS) if they wish to ignore superceded function calls or similar functionality. Metamod leaves this decision to the plugin authors.

Usually this works well, except of course in a situation like this where part of the function's work is to delete the parameter and upon SUPERCEDing a plugin has to take care of that because you'd have a memory leak otherwise.

Personally I've never thought about this situation before and I guess Will Day (the original metamod author) did not either and if he did, concluded that it didn't matter for HL1's interface ;)

2) Haha, that is funny.
2.1.) I wouldn't do it unless really neccessary. If you can ignore superceded events, just ignore them.
2.2.) Sounds like it would work for this situation. You'd still have to think about cases where FreeEvent is called without a call to FireEvent though. Maybe buffer the FreeEvent-ed events, supercede FreeEvent, really free them on next GameFrame? It's getting complicated, see 2.1

Greetings,
PM
__________________
hello, i am pm
PM is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode