Bug 3707 - simple implementation of assert() in bg_lib.h for QVMs
Status: RESOLVED WONTFIX
Alias: None
Product: ioquake3
Classification: Unclassified
Component: Misc
Version: unspecified
Hardware: PC Linux
: P3 enhancement
Assignee: Zachary J. Slater
QA Contact: ioquake3 bugzilla mailing list
URL:
Depends on:
Blocks:
 
Reported: 2008-07-01 14:35 EDT by Ben Millwood
Modified: 2009-10-17 19:35:57 EDT
1 user (show)

See Also:


Attachments
assert() (726 bytes, patch)
2008-07-01 14:36 EDT, Ben Millwood
better assert() (903 bytes, patch)
2009-05-17 19:19 EDT, Ben Millwood

Description Ben Millwood 2008-07-01 14:35:54 EDT
QVM compilation doesn't have access to <assert.h>, so you can't call assert() from any gamecode. This short patch adds assert() to bg_lib.h, which prints a message something like:

********************
ERROR: src/game/g_main.c:529: Assertion `g_entities[ 63 ].client' failed.
********************
----- Server Shutdown (Server crashed: src/game/g_main.c:529: Assertion `g_entities[ 63 ].client' failed.) -----
==== ShutdownGame ====

by calling:

Com_Error( ERR_DROP, __FILE__ ":" str(__LINE__) ": Assertion `" #x "' failed" );

I'm not really sure if this is appropriate to ioq3 given that baseq3 and most mods have their own VMs, but I thought it might be useful nonetheless.
Comment 1 Ben Millwood 2008-07-01 14:36:28 EDT
Created attachment 1800 [details]
assert()
Comment 2 Ben Millwood 2008-07-01 14:39:15 EDT
It's worth noting that this causes inconsistent behaviour for assert() between dynamic libraries and QVMs, but it should do its job on both.

One of the issues with this as a feature is that it isn't optimised out as it should be by NDEBUG, because the build process doesn't differentiate between debug/release builds for the QVMs.
Comment 3 Ben Millwood 2009-05-17 19:19:54 EDT
Created attachment 2066 [details]
better assert()

I put the attached in Tremulous SVN at r1151, where it has seen very little (yet nonzero) usage.

The version I'm attaching now is simpler and doesn't break when expr contains a percent symbol.
Comment 4 Thilo Schulz 2009-10-17 19:35:57 EDT
We don't really need this. Maybe email zakk to add it here:
http://ioquake3.org/extras/patches/