ref: 0d4b3504cc557b5ded1180e2fd00cd210c1024d7
parent: 99d14fa43f2ee64ebf542ab5b7e87e77939c0cdb
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Thu Feb 26 18:10:02 EST 2015
fix buggy linux event handling bullshit this hopefully fully resolves the issues with abnormal exits when entering a new game while already connected, or loading one, etc. afaict, Sys_SendKeyEvents() is called from _Host_Frame(); it in turn calls Key_Event, which, and since we're in the SP menu, enter M_Keydown() → M_SinglePlayer_Key() now, to confirm entering a new game, SCR_ModalMessage is called, but it in turn calls Sys_SendKeyEvents in a loop, which calls Key_Event → M_Keydown → M_SinglePlayerKey, etc. somewhere before or during this mess, the key queue gets horribly disfigured, and the tail and head are either not synced correctly or not pointing to the correct node, causing Sys_SendKeyEvents() to go through almost the whole queue, and shit hits the fan. or race conditions with kproc, or something. Cbuf overflows happen when you mash keys before during the SCR_ModalMessage loop, and then pressing 'y', thus, for each key press, adding the corresponding command, then the ones added from M_SinglePlayer_Key. if you haven't mashed too many keys, Cbuf is big enough to contain all keys. game is reset several times because of this. because of the crazy loop, the stack grows larger and larger, then R_RenderView() exits with 'called without enough stack'. this also happens in the original release on linux/x11, on which this code is based. a quick workaround was to keyq_tail = keyq_head = 0 after Sys_SendKeyEvents' loop, but it had race conditions with kproc or whatever and some keys were sometimes ignored. instead, rewrite the shit and use a channel like the gods intended. if I understood the issue correctly, that's the end of that.