Skip to content

Commit

Permalink
Skip executing FrameDispather on game startup
Browse files Browse the repository at this point in the history
FrameDispatcher is responsible for frame hooks and methods,
that are scheduled via minqlx.delay and minqlx.next_frame decorators.

Before this patch, there could be unwanted situations, where self.game is None
inside those methods. After this patch self.game is always non-None.
  • Loading branch information
em92 committed Dec 6, 2022
1 parent 5ff4abe commit 065fa21
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
void* qagame;
void* qagame_dllentry;

qboolean skipFrameDispatcher;
static void SetTag(void);

void __cdecl My_Cmd_AddCommand(char* cmd, void* func) {
Expand Down Expand Up @@ -156,7 +157,9 @@ void __cdecl My_Com_Printf(char* fmt, ...) {
}

void __cdecl My_SV_SpawnServer(char* server, qboolean killBots) {
skipFrameDispatcher = qtrue;
SV_SpawnServer(server, killBots);
skipFrameDispatcher = qfalse;

// We call NewGameDispatcher here instead of G_InitGame when it's not just a map_restart,
// otherwise configstring 0 and such won't be initialized and we can't instantiate minqlx.Game.
Expand All @@ -165,7 +168,11 @@ void __cdecl My_SV_SpawnServer(char* server, qboolean killBots) {

void __cdecl My_G_RunFrame(int time) {
// Dropping frames is probably not a good idea, so we don't allow cancelling.
FrameDispatcher();

if (!skipFrameDispatcher) {
// Skip running frame hooks while game is not initialized
FrameDispatcher();
}

G_RunFrame(time);
}
Expand Down

0 comments on commit 065fa21

Please sign in to comment.