Skip to content

TF2 Crashes on Plugin Load #505

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

Closed
waldotf opened this issue Feb 20, 2025 · 7 comments
Closed

TF2 Crashes on Plugin Load #505

waldotf opened this issue Feb 20, 2025 · 7 comments
Labels

Comments

@waldotf
Copy link

waldotf commented Feb 20, 2025

Same timing as #504, but probably needs a separate fix. Source.Python fully loads, but segfaults immediately on loading my plugin.

Looks like the plugin interrogating the STV user is breaking something, similar to the condition crashing Sourcemod (alliedmodders/sourcemod#2264). Running under gdb, I get this stack trace (truncated the Python calls):

GDB stack trace
#0  0xf62d73aa in CBaseServer::UserInfoChanged(int) () from target:/srv/srcds/bin/engine_srv.so
#1  0xf627f052 in CBaseClient::SetName(char const*) () from target:/srv/srcds/bin/engine_srv.so
#2  0xf627c946 in CBaseClient::Connect(char const*, int, INetChannel*, bool, int) () from target:/srv/srcds/bin/engine_srv.so
#3  0xf62c45a3 in CGameClient::Connect(char const*, int, INetChannel*, bool, int) () from target:/srv/srcds/bin/engine_srv.so
#4  0xf62d88df in CBaseServer::CreateFakeClient(char const*) () from target:/srv/srcds/bin/engine_srv.so
#5  0xf62bb7b1 in CVEngineServer::CreateFakeClientEx(char const*, bool) () from target:/srv/srcds/bin/engine_srv.so
#6  0xecd5d6b7 in boost::python::objects::caller_py_function_impl<boost::python::detail::caller<int (IVEngineServer::*)() const, boost::python::default_call_policies, boost::mpl::vector2<int, IVEngineServer&> > >::operator()(_object*, _object*) () from target:/srv/srcds/tf/addons/source-python/bin/core.so
#7  0xed12a998 in boost::python::objects::function::call(_object*, _object*) const () from target:/srv/srcds/tf/addons/source-python/bin/core.so
#8  0xed12aba5 in boost::detail::function::void_function_ref_invoker0<boost::python::objects::(anonymous namespace)::bind_return, void>::invoke(boost::detail::function::function_buffer&) ()
   from target:/srv/srcds/tf/addons/source-python/bin/core.so
#9  0xed133cfa in boost::python::handle_exception_impl(boost::function0<void>) () from target:/srv/srcds/tf/addons/source-python/bin/core.so
#10 0xed1295e2 in function_call () from target:/srv/srcds/tf/addons/source-python/bin/core.so
#11 0xed6b0046 in PyObject_Call (func=0xcd7bd10, args=args@entry=0xe75eb94c, kwargs=kwargs@entry=0x0) at Objects/abstract.c:2246
#12 0xed6ccffb in property_descr_get (self=0xee21e7d4, obj=0xee226224, type=0xee2181fc) at Objects/descrobject.c:1384
#13 0xed70e50f in _PyObject_GenericGetAttrWithDict (obj=obj@entry=0xee226224, name=name@entry=0xee21e7a0, dict=dict@entry=0x0) at Objects/object.c:1060
#14 0xed70e73b in PyObject_GenericGetAttr (obj=0xee226224, name=0xee21e7a0) at Objects/object.c:1121
#15 0xed70de85 in PyObject_GetAttr (v=v@entry=0xee226224, name=0xee21e7a0) at Objects/object.c:891
#16 0xed79d566 in _PyEval_EvalFrameDefault (f=0xe7f5edac, throwflag=0) at Python/ceval.c:2821
#17 0xed799cbc in PyEval_EvalFrameEx (f=f@entry=0xe7f5edac, throwflag=throwflag@entry=0) at Python/ceval.c:718
#18 0xed79a683 in _PyEval_EvalCodeWithName (_co=_co@entry=0xe9216cd8, globals=globals@entry=0xe921a48c, locals=locals@entry=0xec7f3504, args=args@entry=0x0, argcount=argcount@entry=0,
    kwnames=kwnames@entry=0x0, kwargs=kwargs@entry=0x4, kwcount=kwcount@entry=0, kwstep=kwstep@entry=2, defs=defs@entry=0x0, defcount=defcount@entry=0, kwdefs=kwdefs@entry=0x0,
    closure=closure@entry=0x0, name=name@entry=0x0, qualname=qualname@entry=0x0) at Python/ceval.c:4128
#19 0xed79ad56 in PyEval_EvalCodeEx (_co=0xe9216cd8, globals=0xe921a48c, locals=locals@entry=0xec7f3504, args=args@entry=0x0, argcount=argcount@entry=0, kws=kws@entry=0x0, kwcount=kwcount@entry=0,
    defs=defs@entry=0x0, defcount=defcount@entry=0, kwdefs=kwdefs@entry=0x0, closure=0x0) at Python/ceval.c:4149
#20 0xed796722 in builtin___build_class__ (self=0xee32257c, args=0xe757f22c, kwds=0x0) at Python/bltinmodule.c:170
#21 0xed70b087 in _PyCFunction_FastCallDict (func_obj=func_obj@entry=0xee322644, args=args@entry=0xec99676c, nargs=nargs@entry=2, kwargs=kwargs@entry=0x0) at Objects/methodobject.c:231
#22 0xed70b34c in _PyCFunction_FastCallKeywords (func=func@entry=0xee322644, stack=stack@entry=0xec99676c, nargs=2, kwnames=kwnames@entry=0x0) at Objects/methodobject.c:295
#23 0xed79aafc in call_function (pp_stack=pp_stack@entry=0xffeaea1c, oparg=oparg@entry=2, kwnames=kwnames@entry=0x0) at Python/ceval.c:4798
#24 0xed79e9e3 in _PyEval_EvalFrameDefault (f=0xec99662c, throwflag=0) at Python/ceval.c:3284
#25 0xed799cbc in PyEval_EvalFrameEx (f=f@entry=0xec99662c, throwflag=throwflag@entry=0) at Python/ceval.c:718
#26 0xed79a683 in _PyEval_EvalCodeWithName (_co=_co@entry=0xe9216de0, globals=globals@entry=0xe921a48c, locals=locals@entry=0xe921a48c, args=args@entry=0x0, argcount=argcount@entry=0,
    kwnames=kwnames@entry=0x0, kwargs=kwargs@entry=0x4, kwcount=kwcount@entry=0, kwstep=kwstep@entry=2, defs=defs@entry=0x0, defcount=defcount@entry=0, kwdefs=kwdefs@entry=0x0,
    closure=closure@entry=0x0, name=name@entry=0x0, qualname=qualname@entry=0x0) at Python/ceval.c:4128
#27 0xed79ad56 in PyEval_EvalCodeEx (_co=_co@entry=0xe9216de0, globals=globals@entry=0xe921a48c, locals=locals@entry=0xe921a48c, args=args@entry=0x0, argcount=argcount@entry=0, kws=kws@entry=0x0,
    kwcount=kwcount@entry=0, defs=defs@entry=0x0, defcount=defcount@entry=0, kwdefs=kwdefs@entry=0x0, closure=closure@entry=0x0) at Python/ceval.c:4149
#28 0xed79adcb in PyEval_EvalCode (co=co@entry=0xe9216de0, globals=globals@entry=0xe921a48c, locals=locals@entry=0xe921a48c) at Python/ceval.c:695
#29 0xed797cbe in builtin_exec_impl (module=0xee32257c, locals=0xe921a48c, globals=0xe921a48c, source=0xe9216de0) at Python/bltinmodule.c:974
#30 builtin_exec (module=0xee32257c, args=0xe9918a2c) at Python/clinic/bltinmodule.c.h:281
#31 0xed70b1e5 in PyCFunction_Call (func=func@entry=0xee322a7c, args=args@entry=0xe9918a2c, kwds=kwds@entry=0xec806fcc) at Objects/methodobject.c:114
#32 0xed7a1949 in do_call_core (kwdict=0xec806fcc, callargs=0xe9918a2c, func=0xee322a7c) at Python/ceval.c:5063
#33 _PyEval_EvalFrameDefault (f=0xecaa062c, throwflag=0) at Python/ceval.c:3366
#34 0xed799cbc in PyEval_EvalFrameEx (f=f@entry=0xecaa062c, throwflag=throwflag@entry=0) at Python/ceval.c:718
#35 0xed79a683 in _PyEval_EvalCodeWithName (_co=_co@entry=0xee32f9c0, globals=globals@entry=0xee2c71bc, locals=locals@entry=0x0, args=args@entry=0xe9933880, argcount=argcount@entry=3,
    kwnames=kwnames@entry=0x0, kwargs=kwargs@entry=0xe993388c, kwcount=kwcount@entry=0, kwstep=kwstep@entry=1, defs=defs@entry=0x0, defcount=defcount@entry=0, kwdefs=kwdefs@entry=0x0,
    closure=closure@entry=0x0, name=name@entry=0xee30d800, qualname=qualname@entry=0xee30d800) at Python/ceval.c:4128
#36 0xed79a9db in fast_function (kwnames=0x0, nargs=3, stack=<optimized out>, func=0xee30becc) at Python/ceval.c:4939
#37 call_function (pp_stack=pp_stack@entry=0xffeaee6c, oparg=oparg@entry=3, kwnames=kwnames@entry=0x0) at Python/ceval.c:4819
#38 0xed79e9e3 in _PyEval_EvalFrameDefault (f=0xe9933734, throwflag=0) at Python/ceval.c:3284
#39 0xed799cbc in PyEval_EvalFrameEx (f=f@entry=0xe9933734, throwflag=throwflag@entry=0) at Python/ceval.c:718
#40 0xed799d7d in _PyFunction_FastCall (co=<optimized out>, args=<optimized out>, nargs=2, globals=0xee2c8f04) at Python/ceval.c:4880
...

Attempting to rebuild against the updated hl2sdk (alliedmodders/hl2sdk@ebd971b) runs into a bunch of missing typedefs -- looks like some more patching is needed. Not surprising since they're incorporating the shiny new tf2 2013 SDK.

@waldotf
Copy link
Author

waldotf commented Apr 12, 2025

I hacked together a functioning build (for TF2/Linux only) based on Python 3.12. My fork is pretty messy, but it should be usable for anyone looking to do something similar: https://github.com/waldotf/Source.Python . Here's the compiled addons/ folder, which is working fine for my purposes: https://mega.nz/file/5WpHyZIZ#DuiLu2-Xe8qzAtXfeMaE2VZGCd3R6zUWv0fuex2-VjQ . Note that this sets VERSION=726.

I blindly bundled the same site-packages dependencies as the previous 3.6.X version did, and I did whatever simple hotfixing was needed to get the source-python package capable of loading my plugin. I anticipate @Ayuto will build for Python 3.13, so don't get too comfortable, though I had surprisingly few patches to make to my plugin to work with the newer version. The scripts/submodule setup in my fork should be useful for anyone looking to build Linux binaries, so hopefully it's helpful for 3.13 work as well.

Big thanks to @verstatx, @spitice, and @benjl for the progress they made on public forks, as well as to @Ayuto for answering some questions I had about the build process.

@CookStar
Copy link
Contributor

All four of you did a wonderful job.
Just out of curiosity, did you have any kind of communication with them in public?

@waldotf
Copy link
Author

waldotf commented Apr 13, 2025

Just out of curiosity, did you have any kind of communication with them in public?

Nope, I just monitored the Github forks for this project and looked for anyone working on the same problems. Probably could have saved some time with proper communication, but I'm far enough outside my ambit that I assumed anyone with the motivation and know-how wouldn't get much out of it.

@Ayuto
Copy link
Member

Ayuto commented Apr 16, 2025

Just wanted to let you know that I'm finally working on the update. You can keep track of the work here:
https://github.com/Source-Python-Dev-Team/Source.Python/tree/py313

The Windows portion is already finished and the servers are starting. Next steps will be Linux and updating game data. If anyone is volunteering to update the game data it would be a great help!

If everything is working again we can focus on refactoring some parts of SP like introducing Git submodules.

I would also like to apologize for the super massive delay. I have been busy with many other things and the required changes were a lot bigger than expected.

Hopefully, the new version will be out until the weekend.

@srpg
Copy link
Contributor

srpg commented Apr 17, 2025

I have compiled css version to windows it seem to work almost fully(after updating game data), but OnTakeDamage code doesn't work for me, it gives following error:
[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\plugins\rpg\rpg.py", line 3733, in pre_damage
if info.attacker == info.inflictor:
^^^^^^^^^^^^^^

ValueError: Conversion from "BaseHandle" (<_entities.BaseEntityHandle object at 0x1EAA1728>) to "Index" failed.

@Ayuto
Copy link
Member

Ayuto commented Apr 18, 2025

New builds are available on our download page!

If anything is not working, please create a new issue. Tomorrow I will check the BaseHandle conversion error, fix the wiki layout/design and publish another release to reflect the latest changes.

@Ayuto
Copy link
Member

Ayuto commented Apr 19, 2025

I have compiled css version to windows it seem to work almost fully(after updating game data), but OnTakeDamage code doesn't work for me, it gives following error: [SP] Caught an Exception: Traceback (most recent call last): File "..\addons\source-python\plugins\rpg\rpg.py", line 3733, in pre_damage if info.attacker == info.inflictor: ^^^^^^^^^^^^^^

ValueError: Conversion from "BaseHandle" (<_entities.BaseEntityHandle object at 0x1EAA1728>) to "Index" failed.

This actually works fine for me.

from entities import TakeDamageInfo
from entities.hooks import EntityCondition, EntityPreHook
from memory import make_object

@EntityPreHook(EntityCondition.is_bot_player, 'on_take_damage')
@EntityPreHook(EntityCondition.is_human_player, 'on_take_damage')
def _pre_take_damage(stack_data):
    info = make_object(TakeDamageInfo, stack_data[1])
    print(info.attacker)
    print(info.inflictor)

If the issue still persists, please create a new issue with steps to reproduce. I will now close the actual issue.

@Ayuto Ayuto closed this as completed Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants
@Ayuto @waldotf @CookStar @srpg and others