Page 1 of 1

Custom event conflicts with events prehook

Posted: Wed Aug 27, 2014 6:33 pm
by Hedgehog
Server crashes when a custom event is being fired and a PreHook for events is active. How to fix it?

Syntax: Select all

from core import PLATFORM

from events import Event
from events import GameEvent
from events.custom import CustomEvent
from events.manager import GameEventManager
from events.resource import ResourceFile
from events.variable import ShortVariable

from memory import Convention, Argument, Return
from memory import get_object_pointer
from memory import make_object
from memory.hooks import PreHook


class Test_Event(CustomEvent):
userid = ShortVariable()


res = ResourceFile('test_events_file', Test_Event)
res.write()
res.load_events()


PRE_EVENT_FUNC = get_object_pointer(GameEventManager).make_virtual_function(
7 if PLATFORM == 'windows' else 8,
Convention.THISCALL,
(Argument.POINTER, Argument.POINTER, Argument.BOOL),
Return.VOID
)


@PreHook(PRE_EVENT_FUNC)
def pre_events(arguments):
print('pre_events')

game_event = make_object(GameEvent, arguments[1])
print(game_event.get_name())


@Event
def test_event(event):
print('Test_Event')


@Event
def player_spawn(event):
print('spawn')

Test_Event(userid=event.get_int('userid')).fire()

Posted: Wed Aug 27, 2014 7:38 pm
by Ayuto
Thank you for reporting! I just tested this and it seems that it only crashes if you fire your event in another event.

We will look into this issue.

Posted: Thu Aug 28, 2014 9:27 am
by Ayuto
Did you test your code on Linux or Windows?

Posted: Thu Aug 28, 2014 10:13 am
by Hedgehog
Windows only

CS:S, July 17 build

Posted: Thu Aug 28, 2014 8:01 pm
by Ayuto
Okay, for me it only crashed on Windows. However, this seems to "fix" the issue.[python]@Event
def player_activate(event):
tick_delays.delay(0, Test_Event(userid=2).fire)[/python]I'm still not sure what causes the crash, but when I comment out this line (which disables post-hooks) it works fine. But that still doesn't make sense to me.

Edit: DynamicHooks is at fault here. This happens if two threads call the same hooked function at the same time or when a hooked function calls itself, which is currently happening here. It will screw up the registeres and return address, which results in a server crash. I will need to update DynamicHooks at some time to handle these situations, but for now use the workaround with the delay.

Posted: Sun Oct 26, 2014 1:57 am
by your-name-here
Ayuto wrote:Okay, for me it only crashed on Windows. However, this seems to "fix" the issue.Python:
  1. @Event
  2. def player_activate(event):
  3. tick_delays.delay(0, Test_Event(userid=2).fire)



I'm still not sure what causes the crash, but when I comment out this line (which disables post-hooks) it works fine. But that still doesn't make sense to me.

Edit: DynamicHooks is at fault here. This happens if two threads call the same hooked function at the same time or when a hooked function calls itself, which is currently happening here. It will screw up the registeres and return address, which results in a server crash. I will need to update DynamicHooks at some time to handle these situations, but for now use the workaround with the delay.


What kind of exception are you receiving? Is it a null pointer crash or are you blowing out your stack?