forked from NeotokyoRebuild/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround for Linux shaders breakage (NeotokyoRebuild#587)
Fix NeotokyoRebuild#438 This is a hack around the vision mode shaders sporadically breaking on Linux builds. It seems that for whatever reason, the shader state cached at the `glshaders.cfg` file somehow leads to the corruption upon successive runs of the game. This patch manually sets the `mat_autosave_glshaders cvar` to 0 at client initialization, such that the game won't generate the problematic file upon exit. It also deletes the `glshaders.cfg` file if it already existed (in which case it's too late to fix the problem for that launch of the game, but future launches should work correctly due to the cvar switch, and the file now being gone). This can be the case for users who didn't do a clean reinstall of the game, and have the file stored from a previous launch of the game (or who for whatever reason had an autoexec overriding the `mat_autosave_glshaders` behaviour, which would take precedence over the runtime cvar change). Ideally, we should figure out what's really going wrong here at the shader system and/or precaching level, but this should suffice for avoiding the bug. For more discussion, see: * NeotokyoRebuild#587 * NeotokyoRebuild#438 (comment)
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "neo_fixup_glshaders.h" | ||
#ifdef LINUX | ||
|
||
// Engine | ||
#include "filesystem.h" | ||
#include "icvar.h" | ||
|
||
// Stdlib | ||
#include <source_location> | ||
|
||
// memdbgon must be the last include file in a .cpp file!!! | ||
#include "tier0/memdbgon.h" | ||
|
||
// NEO HACK (Rain): This is a hack around a vision shaders corruption on Linux. | ||
// For details, see: https://github.com/NeotokyoRebuild/neo/pull/587 | ||
void FixupGlShaders(IFileSystem* filesystem, ICvar* cvar) | ||
{ | ||
constexpr auto filename = "glshaders.cfg", | ||
pathID = "MOD", | ||
funcName = std::source_location::current().function_name(); | ||
|
||
// This prevents the game from generating the problematic file on exit. | ||
// There's also a "mat_autoload_glshaders", but it seems by the time we load, | ||
// it's too late for that to take an effect, at least via this route. | ||
// The client can still override this by including a command in their autoexec, | ||
// if they really want to. | ||
constexpr auto cvarname = "mat_autosave_glshaders"; | ||
ConVar* autosaveGlShaders; | ||
if (!(autosaveGlShaders = cvar->FindVar(cvarname))) | ||
{ | ||
Warning("%s: cvar %s not found\n", funcName, cvarname); | ||
return; | ||
} | ||
autosaveGlShaders->SetValue(false); | ||
|
||
// If the problematic file doesn't exist, we're done. | ||
if (!filesystem->FileExists(filename, pathID)) | ||
{ | ||
return; | ||
} | ||
|
||
// But if it does, we're too late to fix it for this launch... | ||
// However, we can delete the file, which together with the convar set above | ||
// should prevent it from being created again on successive restarts of the game. | ||
|
||
// This should never happen, but just in case the relative mod path lookup somehow fails. | ||
if (filesystem->IsDirectory(filename, pathID)) | ||
{ | ||
Warning("%s: Expected to find a file at %s path %s, but it was a dir\n", | ||
funcName, pathID, filename); | ||
return; | ||
} | ||
|
||
filesystem->RemoveFile(filename, pathID); | ||
} | ||
#endif // LINUX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef NEO_FIXUP_GLSHADERS_H | ||
#define NEO_FIXUP_GLSHADERS_H | ||
#ifdef _WIN32 | ||
#pragma once | ||
#endif | ||
#ifdef LINUX | ||
|
||
class ICvar; | ||
class IFileSystem; | ||
|
||
void FixupGlShaders(IFileSystem* filesystem, ICvar* cvar); | ||
|
||
#endif // LINUX | ||
#endif // NEO_FIXUP_GLSHADERS_H |