Skip to content

Fix cgameExport_t::Init signature mismatch with OpenJK GetModuleAPI - #460

Open
pdewilde wants to merge 1 commit into
Razish:masterfrom
pdewilde:fix/cgame-init-abi
Open

pdewilde wants to merge 1 commit into
Razish:masterfrom
pdewilde:fix/cgame-init-abi

Conversation

@pdewilde

@pdewilde pdewilde commented Nov 21, 2026 •

Copy link
Copy Markdown

Problem

OpenJK's engine invokes cge->Init with 3 arguments (matching codemp/cgame/cg_public.h):

void (*Init)(int serverMessageNum, int serverCommandSequence, int clientNum);

In JA++, cgameExport_t::Init in cgame/cg_public.h declares a 4th qboolean demoPlayback parameter, and GetModuleAPI() in cgame/cg_main.cpp assigns cge.Init = CG_Init (a 4-argument function) directly.

Note that JA++'s own legacy vmMain CG_INIT case in the same file (cgame/cg_main.cpp:2260) already handles the 3-argument engine call by passing qfalse explicitly:

CG_Init(arg0, arg1, arg2, qfalse);

On native x86/x86_64 calling conventions this mismatch goes unnoticed (reading an uninitialized 4th register/stack slot for demoPlayback), but it is undefined behavior in C/C++ and traps immediately on strict indirect-call targets (such as WebAssembly call_indirect or Clang CFI).

Fix

  • Update cgameExport_t::Init in cgame/cg_public.h to the 3-argument signature matching OpenJK.
  • Add a static CG_InitAPI(int serverMessageNum, int serverCommandSequence, int clientNum) wrapper in cgame/cg_main.cpp that forwards to CG_Init(..., qfalse) (matching vmMain), and assign cge.Init = CG_InitAPI in GetModuleAPI().

@pdewilde pdewilde changed the title Fix cgameExport_t::Init signature mismatch with OpenJK CGAME_API_VERSION 2 Fix cgameExport_t::Init signature mismatch with OpenJK GetModuleAPI Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant