New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server crash on player.teleport? #157

Closed
Velocity-plus opened this Issue Oct 11, 2016 · 8 comments

Comments

Projects
None yet
5 participants
@Velocity-plus

Velocity-plus commented Oct 11, 2016

Description

  • Game: Counter-Strike: Global Offensive
  • OS: Linux

Following code crashes server:

from listeners import OnPlayerRunCommand
from mathlib import Vector


@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
    player.teleport(velocity=Vector(100,100,100)) # Triggers crash

Original Issue:

from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook
from memory import make_object
from messages import SayText2
from players.entity import Player

TARGET_CLASSNAME = 'flashbang_projectile'

@EntityPreHook(
    EntityCondition.equals_entity_classname(TARGET_CLASSNAME),
    "start_touch")
def pre_start_touch(args):
    entity = make_object(Entity, args[0])

    if entity.classname != TARGET_CLASSNAME:
        return
    other = make_object(Entity, args[1])
    if not other.is_player():
        return

    player = make_object(Player, args[1])
    player.teleport(velocity=Vector(100,100,100)) # Triggers crash

@invincibleqc invincibleqc added the bug label Oct 11, 2016

@invincibleqc

This comment has been minimized.

Contributor

invincibleqc commented Oct 11, 2016

Dynamically calling a function within a hook can have undefined behaviors. Try to execute the call on the next frame:

from listeners import OnPlayerRunCommand
from listeners.tick import Delay

@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
    Delay(0, player.teleport, velocity=Vector(100,100,100))

Also, if you only want to push the player, you could always use Player.base_velocity which applies the given Vector instance to the current velocity of the player.

@KirillMysnik

This comment has been minimized.

Member

KirillMysnik commented Oct 11, 2016

Originally reported for start_touch EntityPreHook: http://forums.sourcepython.com/viewtopic.php?p=9063#p9063
Probably related: http://forums.sourcepython.com/viewtopic.php?f=10&t=1158

I wonder when the crash happens in this case.
I've had issues with teleport, but all crashes seemed to happen AFTER the function was successfully called. I mean, inserting a print after teleport, for example, resulted in a successful print and then crashed. The function was called from inside of OnEntityOutput listener. So I guess it crashed when the hooked function was returning control.

Oh, I have experienced this on Windows. While the issue at the second link only happened on Linux, and call to the function itself was crashing the server.

@Ayuto

This comment has been minimized.

Member

Ayuto commented Oct 12, 2016

@Velocity-plus I guess you are testing on Linux. Is that right?

@Velocity-plus

This comment has been minimized.

Velocity-plus commented Oct 13, 2016

Yes I currently am, and I have updated both posts now.

@KirillMysnik

This comment has been minimized.

Member

KirillMysnik commented Oct 15, 2016

@invincibleqc Since we're on it, what kind of "undefined behaviors" could this lead to? I've had some weird crashes in my plugin, but was unable to consistently reproduce the crash - it seemed rather random. Do random crashes fall under "undefined behaviour" definition?

Also, I think it's good to clarify somewhere that a "hook" and "dynamically calling a function" might be things not that obvious. For example, PreEvent is based on hooks, OnEntityOutput listener is also based on them. On the other side, Player.view_angle property is based on teleport function. So the issue applies to all of them, too. But these are masked.
Combine this fact with "undefined behavior" and you have a real good case of random, untraceble crash in your plugin.
I believe there should be a note in the docs, like "this feature is hook-based" or "this feature uses function dynamically called".

@Ayuto

This comment has been minimized.

Member

Ayuto commented Oct 16, 2016

You are supposed to be able to call a function dynamically within a hook, so this is something we definitely need to fix. And if we have fixed it, there is no need to mention that anywhere.

I really need some time to figure out what's wrong, but unfortunately my time is currently very limited.

@njanke96

This comment has been minimized.

Contributor

njanke96 commented Aug 28, 2017

I also have this issue. It occurs when calling within an OnEntityOutput listener for the OnStartTouch output. Alternatively, setting player.origin and player.velocity works fine.

EDIT: Oops I lied. That doesn't work either.

@Ayuto

This comment has been minimized.

Member

Ayuto commented Aug 28, 2017

OnEntityOutput uses a hook internally. Try the suggested workaround (delaying the call).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment