Fix vprof crashing in some games (#1541)

Some engines are very sensitive to exactly when in a frame vprof is
enabled, the vprof commands use a special command registration method
to defer their execution to the start of the next frame. Instead of
starting/stopping vprof directly ourselves, use the built-in commands
to ensure that the timing is correct and the server does not crash.

Fixes #1162
This commit is contained in:
Asher Baker 2021-07-18 19:08:36 +01:00 committed by GitHub
parent 2d241316c7
commit f8f5a18d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View File

@ -36,11 +36,6 @@
VProfTool sVProfTool; VProfTool sVProfTool;
VProfTool::VProfTool()
: active_(false)
{
}
void void
VProfTool::OnSourceModAllInitialized() VProfTool::OnSourceModAllInitialized()
{ {
@ -62,14 +57,24 @@ VProfTool::Description()
bool bool
VProfTool::Start() VProfTool::Start()
{ {
g_VProfCurrentProfile.Start(); // Some engines are very sensitive to exactly when in a frame vprof is
return IsActive(); // enabled, the vprof commands use a special command registration method
// to defer their execution to the start of the next frame. Instead of
// starting/stopping vprof directly ourselves, we use the built-in commands
// to ensure that the timing is correct and the server does not crash.
//
// g_VProfCurrentProfile.Start();
engine->ServerCommand("vprof_on\n");
return true; // IsActive();
} }
void void
VProfTool::Stop(void (*render)(const char *fmt, ...)) VProfTool::Stop(void (*render)(const char *fmt, ...))
{ {
g_VProfCurrentProfile.Stop(); // See note in VProfTool::Start
//
// g_VProfCurrentProfile.Stop();
engine->ServerCommand("vprof_off\n");
RenderHelp(render); RenderHelp(render);
} }

View File

@ -37,8 +37,6 @@ class VProfTool
public SMGlobalClass public SMGlobalClass
{ {
public: public:
VProfTool();
// IProfilingTool // IProfilingTool
const char *Name() override; const char *Name() override;
const char *Description() override; const char *Description() override;
@ -53,9 +51,6 @@ public:
// SMGlobalClass // SMGlobalClass
void OnSourceModAllInitialized() override; void OnSourceModAllInitialized() override;
private:
bool active_;
}; };
#endif // _include_sourcemod_core_vprof_bridge_h_ #endif // _include_sourcemod_core_vprof_bridge_h_