Skip to content

Commit 50d2223

Browse files
committed
Fix configstring replacement causing the model to be referenced twice on base MOHAA clients
This caused MOHAA clients to crash due to referencing a model that was freed or an unrelated model (reallocation).
1 parent e47790c commit 50d2223

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

code/cgame/cg_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,12 @@ void CG_ProcessConfigString(int num, qboolean modelOnly)
358358

359359
if (hModel != hOldModel) {
360360
if (hOldModel) {
361+
assert(CG_IsHandleUnique(hOldModel));
361362
cgi.R_UnregisterServerModel(hOldModel);
362363
}
363364

364365
cgs.model_draw[num - CS_MODELS] = hModel;
366+
assert(CG_IsHandleUnique(hModel));
365367
}
366368
tiki = cgi.R_Model_GetHandle(hModel);
367369
if (tiki) {

code/server/sv_main.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,25 @@ not have future snapshot_t executed before it is executed
160160
void SV_AddServerCommand( client_t *client, const char *cmd ) {
161161
int index, i;
162162

163-
// this is very ugly but it's also a waste to for instance send multiple config string updates
164-
// for the same config string index in one snapshot
165-
if ( !strncmp(cmd, "cs ", 3) && SV_ReplacePendingServerCommands(client, cmd) ) {
166-
return;
163+
if ( com_protocol->integer >= PROTOCOL_MOHTA_MIN ) {
164+
// Added in 2.0
165+
// Requires spearhead clients.
166+
// Unfortunately in MOHAA 1.11, replacing cs can cause clients to crash
167+
// when an existing model is moved into a lower configstring.
168+
// For example:
169+
// cs 138 models/weapons/mp40.tik
170+
// cs 117 models/weapons/m1_garand.tik
171+
// 1) models/weapons/mp40.tik is already referenced by cs 117, it will cause the model handle to be referenced twice.
172+
// 2) when the client executes "cs 117", it will free up the mp40.tik model, leaving a dangling handle for cs 138.
173+
174+
// FIXME: To make it work on MOHAA clients, reorder configstrings that are sent to clients.
175+
// For example, always put "cs 117" before "cs 138".
176+
177+
// this is very ugly but it's also a waste to for instance send multiple config string updates
178+
// for the same config string index in one snapshot
179+
if ( !strncmp( cmd, "cs ", 3 ) && SV_ReplacePendingServerCommands( client, cmd ) ) {
180+
return;
181+
}
167182
}
168183

169184
// do not send commands until the gamestate has been sent

0 commit comments

Comments
 (0)