Custom event conflicts with events prehook

Please post any questions about developing your plugin here. Please use the search function before posting!
Hedgehog
Member
Posts: 62
Joined: Sun Nov 03, 2013 8:54 pm

Custom event conflicts with events prehook

Postby Hedgehog » Wed Aug 27, 2014 6:33 pm

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()
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed Aug 27, 2014 7:38 pm

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.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Aug 28, 2014 9:27 am

Did you test your code on Linux or Windows?
Hedgehog
Member
Posts: 62
Joined: Sun Nov 03, 2013 8:54 pm

Postby Hedgehog » Thu Aug 28, 2014 10:13 am

Windows only

CS:S, July 17 build
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Aug 28, 2014 8:01 pm

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.
your-name-here
Developer
Posts: 168
Joined: Sat Jul 07, 2012 1:58 am

Postby your-name-here » Sun Oct 26, 2014 1:57 am

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?

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 133 guests