aboutsummaryrefslogtreecommitdiffstats
path: root/al/error.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-05-24 08:43:14 -0700
committerChris Robinson <[email protected]>2023-05-24 08:43:14 -0700
commit49de6777205822816521bd136312dd24a0cf2512 (patch)
tree33fc2e304aea7314a509b8d6093c8e5363e22c42 /al/error.cpp
parent4bfbdbf62dee4cf6c8658da9f2872f5d5e98eddb (diff)
Add a compat option to change the error value with no context
Diffstat (limited to 'al/error.cpp')
-rw-r--r--al/error.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/al/error.cpp b/al/error.cpp
index 9db13947..5c9ebdf8 100644
--- a/al/error.cpp
+++ b/al/error.cpp
@@ -29,7 +29,9 @@
#include <csignal>
#include <cstdarg>
#include <cstdio>
+#include <cstdlib>
#include <cstring>
+#include <limits>
#include <mutex>
#include <vector>
@@ -39,10 +41,12 @@
#include "al/debug.h"
#include "alc/context.h"
#include "almalloc.h"
+#include "alstring.h"
#include "core/except.h"
#include "core/logging.h"
#include "direct_defs.h"
#include "opthelpers.h"
+#include "strutils.h"
bool TrapALError{false};
@@ -99,7 +103,23 @@ AL_API ALenum AL_APIENTRY alGetError(void) noexcept
auto context = GetContextRef();
if(!context) UNLIKELY
{
- static constexpr ALenum deferror{AL_INVALID_OPERATION};
+ static const ALenum deferror{[](const char *envname, const char *optname) -> ALenum
+ {
+ auto optstr = al::getenv(envname);
+ if(!optstr)
+ optstr = ConfigValueStr(nullptr, "game_compat", optname);
+
+ if(optstr)
+ {
+ char *end{};
+ auto value = std::strtoul(optstr->c_str(), &end, 0);
+ if(end && *end == '\0' && value <= std::numeric_limits<ALenum>::max())
+ return static_cast<ALenum>(value);
+ ERR("Invalid default error value: \"%s\"", optstr->c_str());
+ }
+ return AL_INVALID_OPERATION;
+ }("__ALSOFT_DEFAULT_ERROR", "default-error")};
+
WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror);
if(TrapALError)
{