-
-
Notifications
You must be signed in to change notification settings - Fork 191
Improve FunctionReference trace logging with real user stack origin #895
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
Conversation
# Conflicts: # configs/addons/counterstrikesharp/configs/core.json
This reverts commit 946a53c.
|
I actaully forgot to remove the
|
|
All requested changes have been applied:
Let me know if you’d prefer anything split into a separate PR or adjusted further. |
| { | ||
| if (!IsContextSafe()) | ||
| { | ||
| ScriptContext().ThrowNativeError("ScriptCallback::Execute aborted due to invalid context"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, in what scenarios have you encountered that the context is not safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As i remember, sometimes in newer css versions when was warmup and player which was alive changed team, where plugin with eventplayerspawn opened instantly any menu, it stopped recognizing inputs from OnKeyPress excluding the next, previous and close actions. This fixed it for me.
|
LGTM, might need to fix the clang-format issues |
Fixed the clang-format complaint from CI. Good to go now! |
Summary
This PR adds structured callback trace registration to CounterStrikeSharp by capturing the actual user-level stack frame that registered a delegate.
This feature by itself does not change runtime behavior or add logging — it’s purely structural and performance-neutral. It prepares the internal architecture for advanced debugging and crash diagnostics without introducing risk to existing systems.
Why
Old output (completely unhelpful):
[23:40:30.477] CSSharp: Native 5df2e20d was invoked on a non-main threadThis gives no information about which plugin or part of the code triggered it.
New trace (fully traceable via my external MM plugin):
[CALLBACK TRACE] name='MyPlugin+<>c__DisplayClass7_0.<OnMapStart>b__0' callerStack(top)='MyPlugin.OnMapStart @ MyPlugin.cs:42'This reveals exactly which delegate was registered and where — essential for diagnosing crashes, thread violations, or slow callbacks.
Implementation
StackTrace(2, true)insideFunctionReference.CreateWrappedCallback()CounterStrikeSharp,SafeExecutor, compiler-generated closure types)RegisterCallbackTrace(...)This is a backend-only improvement that enables external tooling support.
AcceleratorCSS Integration
This structural change enables native integration with AcceleratorCSS, a Metamod plugin I’ve developed, which hooks into
RegisterCallbackTrace().Once this PR is merged:
AcceleratorCSSwill be fully compatible with all Linux builds of CSSThe plugin is finished and will be released immediately after this PR is merged.
Let me know if you prefer the trace logic behind a config flag, or extracted into a utility. Otherwise, this is backward-safe and ready to merge.