sys: allow the platform to handle crashes after DP does As suggested by divVerent in chat. In SDL builds (including when using -dedicated on the cmdline) the OS handler runs after the user clicks OK on the SDL dialog. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
Revert renamings from 591877ee0c64958303dcbb4f2af3d343a420cf6a Pragmatically speaking, absent any good reason otherwise, naming conventions for functions like Sys_Error should remain consistent with Quake for developer sanity.
PRVM: refactor error handling Cleans up PRVM_Crash() calling and removes redundant code. Directs menu errors to stderr instead of stdout. Aborts if a loop is detected in MVM_error_cmd(), matching Host_Error(). Prevents QC's CSQC_Shutdown() being called when CSQC crashes. Makes cvar prvm_errordump ignore MENUQC crashes. Improves some messages and comments. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cvar: fix many bugs in gamedir, loadconfig, unset, cvar_resettodefaults* commands Fixes a segfault when Cvar_RestoreInitState() deleted cvars (null ptr deref). Fixes an infinite loop in Host_LoadConfig_f() due to calling Cbuf_Execute() from inside Cbuf_Execute() via Host_AddConfigText(). Fixes `unset` being able to delete autocvars while they're in use by QC. Fixes Cvar_RestoreInitState() not updating autocvars when necessary. Fixes Cvar_RestoreInitState() not calling cvar callbacks. Fixes Cvar_RestoreInitState() sometimes restoring such that .string doesn't match .value, or such that .defstring is wrong. This was caused by Cvar_SaveInitState() saving only string pointers and not strings. Fixes CF_READONLY cvars like gl_info_* getting restored/reset. It doesn't make sense for any of these to be changed by code outside their own subsystems. Fixes Xonotic menu QC errors caused by Host_LoadConfig_f deleting cvars before calling QC's m_shutdown(). Deduplicates and simplifies cvar deletion code, see also 05a5ed884366d3a1c8e211168efc19b61867cfca Saves a little memory by storing only minimal init state data for Cvar_RestoreInitState(), and by relaxing alignment requirements in _Mem_strdup(). Improves some warns and docs and tidies up a little. Removes `vid_restart` from `gamedir`, it usually isn't needed because current DP applies many vid_ cvar changes without it, and because of the ubiquity of flat panel displays. Fixes https://gitlab.com/xonotic/darkplaces/-/issues/354 Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
sys: refactor the clean shutdown process After all the other refactors finally we can clean this up. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
sys: improve error and crash handling Renames Sys_Error to Sys_Abort (now using the Engine Abort message) for clarity (as distinct from the non-fatal Host_Error). Includes the engine version in the Crash and Abort SDL dialogs. Linux: includes the glibc backtrace in the Engine Crash SDL dialog. Fixes CTRL+C not working while the SDL dialog is open. Fixes a double Sys_Error/Sys_Abort when memory corruption was detected. Windows: omits colours when printing a Crash to stderr (not supported). Makes signal handling (mostly) POSIX async-signal-safe. Fixes a slight bug in PRVM_ShortStackTrace(). Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
com: rename BSD strlcpy and strlcat The C standard reserves str* and mem* for the implementation. Checking for BSD or OS X is not a robust way to determine if libc provides these (eg glibc may implement them). Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
sys: write significant engine and QC errors to stderr A server configured with -nostdout or sys_stdout 0 will now be able to report bugs. Retrieves stdio stream FDs instead of assuming they're always 0,1,2. Fixes some comment!=code discrepancies. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
sys: make stdout/stderr configurable during runtime Adds cvar sys_stdout which offers the same behaviours as the -nostdout and -stderr cmdline options and is initialised by them if they're passed. Makes -noterminal cmdline option a synonym for -nostdout, previously it was effectively the same but less efficient. Platforms with the fcntl() syscall (ie non-Windows): Changes to non-blocking stdout/stderr by default to prevent stutters and halts in certain scenarios. Adds cvar sys_stdout_blocks for enabling blocking stdout/stderr if required. Retrieves stdio stream FDs instead of assuming they're always 0,1,2. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
host: log graceful shutdown (config, history) Stopping demo recording should already get a message. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
sys: implement signal handling on all platforms Prints a stack trace when crashing if using glibc. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
sys: commenting and tidying Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
deduplicate Sys_Shutdown() Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
deduplicate main() Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cbuf: recycle node after it executes, clear commands on Host_Error() This reverts 626658074c8dd5c2288becd836103e2efdb9b741 which looks like a potentially racy or non-threadsafe approach, and instead prevents problems by clearing the command buffers if Host_Error() is called and doesn't shut down DP. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
Sys_Sleep overhaul One function to rule them all, and in the darkplaces sleep threads. Makes sub-millisecond accuracy available on Windows. Increases the number of sockets we can monitor on Windows. Improves Curl_Select() a little. Updates flags of some timing-related cvars. Cleans up disorganised and duplicate code. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
build: fix buildstring The revision was always "-", there was code duplication and inconsistency, the meaning of some strings was unclear. Frees up some space in the `status` "version:" line by moving gamenetworkfiltername to "protocol:" which seems like a more relevant section anyway. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
vid: move sound start/restart out of video start/restart According to the comments in S_Restart_f() we must not restart sound while running a map, but `vid_restart` did do that... Also simplified/consolidated code paths a little. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
vid: misc cleanups Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cbuf: fix a 1 frame delay of keybind inputs This was a regression (from div0-stable) introduced in the refactoring. Signed-off-by: bones_was_here <bones_was_here@xonotic.au>