Stopped all the compiler warnings
by David Stewart Zink · in Torque Game Engine · 08/12/2001 (9:48 am) · 12 replies
I made a run through the code and stripped out all the compiler warnings; turned up a couple of clear bugs that way, and quite a few things that would require a lot of thought or insight that I don't yet have to figure out whether they're bugs or not.
I could use a lot of this code as course material for "how to get in trouble with C++", but compared to other engine code I've seen it's actually pretty clean.
Obviously it was in good shape a while back, and then some wag turned off compiler warnings and changed some basic stuff, giving you the million warnings/errors you see today.
I'm pretty busy--have to work-work today (Sunday) I'm afraid--and my wife will probably package my discoveries up and try to feed them back into the source tree.
I could use a lot of this code as course material for "how to get in trouble with C++", but compared to other engine code I've seen it's actually pretty clean.
Obviously it was in good shape a while back, and then some wag turned off compiler warnings and changed some basic stuff, giving you the million warnings/errors you see today.
I'm pretty busy--have to work-work today (Sunday) I'm afraid--and my wife will probably package my discoveries up and try to feed them back into the source tree.
#2
Unfortunately the rules to C++ dictate that the cast-to-bool operator doesn't get invoked in that context, though what was getting invoked amounted to the same thing so stuff seemed to work.
I replaced it with the if(mInteriorRes.isNull()) idiom (isNull() already existed and does the right thing).
In general don't override cast-to-primitive-type, because the compiler will find all sorts of cunning opportunities to use them. Settle on an idiom like "toBool()" or "toLong()", or even better: methods with sematically useful names like "isNull()".
08/12/2001 (10:20 am)
The next most pervasive problem was with the resource class; someone overrode the cast-to-bool operator (bad thinking, that) and then used the idiom if (bool(mInteriorRes) == false) to see if the pointer hidden in the reource.autoptr was null and if not null was invalid.Unfortunately the rules to C++ dictate that the cast-to-bool operator doesn't get invoked in that context, though what was getting invoked amounted to the same thing so stuff seemed to work.
I replaced it with the if(mInteriorRes.isNull()) idiom (isNull() already existed and does the right thing).
In general don't override cast-to-primitive-type, because the compiler will find all sorts of cunning opportunities to use them. Settle on an idiom like "toBool()" or "toLong()", or even better: methods with sematically useful names like "isNull()".
#3
08/12/2001 (10:21 am)
platformX86UNIX/platformGL.h includes the multitexture stuff twice, the first time incompletely but preventing the second. I'd say someone was in a hurry! ;)
#4
if (obj->getType() & PlayerObjectType)
U32 test = 0;
which of course you can't comment out witout verifying that getType() has no side-effects, but I did anyways;)
08/12/2001 (10:26 am)
sceneGraph/sceneTraversal.cc has the beauty:if (obj->getType() & PlayerObjectType)
U32 test = 0;
which of course you can't comment out witout verifying that getType() has no side-effects, but I did anyways;)
#5
08/12/2001 (10:39 am)
Yeah, the platformX86UNIX/platformGL.h is FUGLY^10. It works though :-).
#6
obviously a cut and paste error, but it got me thinking: if some other method had a similar bug, say:
08/12/2001 (11:13 am)
This was one obvious bug:DbgFileView::DbgFileView()
{
VECTOR_SET_ASSOCIATION(mFileView);
mFileName = NULL;
mPCFileName = NULL;
mPCCurrentLine = -1;
mBlockStart = -1;
mBlockEnd = -1;
mFindString[0] = '[[6281faeda635b]]';
S32 mFindLineNumber = -1;
mSize.set(1, 0);
}obviously a cut and paste error, but it got me thinking: if some other method had a similar bug, say:
void DbgFileView::setLineNumber(S32 l)
{
S32 mFindLineNumber = l;
debugLog("setting line number: %d\n", (int)l);
}then (A) the code won't work; (b) you'll get an "unused variable error", (c) commenting the line out is harmless, but the code still won't work, (d) the real problem is the compiler is too stupid to tell you "automatic variable has same name as class variable", so you won't see what the actual bug is.
#7
08/12/2001 (11:17 am)
By "stopped all warnings" I mean it (a) still works, (b) compiles under VS6 warning level 4 with no warnings *except* for the legacy PNG, JPEG code etc., and (c) compiles under linux "g++ -Wall -Werror".
#8
Obviously someone at gg should look them over and either explicitly cast the argument to mAbs("Yes i MEANT to do this") or use mFabs instead.
08/12/2001 (11:26 am)
Something else that requires thought: There are several places where floats are multiplied against each other and the absolute value of the result is assigned to a float. Unfortunately the absolute value function sometimes used--mAbs()--takes an integer argument and returns an integer. This silent rounding is of course invisible with conversion warnings blocked. But is it intentional? It didn't seem to make a lot of sense, so I substituted mFabs() in my code to see what happened. Down the road when I understand better what's happening I'll figure out the correct thing.Obviously someone at gg should look them over and either explicitly cast the argument to mAbs("Yes i MEANT to do this") or use mFabs instead.
#9
08/12/2001 (1:17 pm)
I have diffs for David's changes, as generated by p4 describe. I can email 'em or stick 'em up to be grabbed.
#10
Here is the error i get when i try to batch build the v12 engine.dsw and the tools.dsw. Please help
08/13/2001 (6:19 pm)
Error executing link.exe.Here is the error i get when i try to batch build the v12 engine.dsw and the tools.dsw. Please help
#11
Here is the error i get when i try to batch build the v12 engine.dsw and the tools.dsw. Please help
Please give us more information. "Error executing link.exe" does not give us any details about the error.
Although, using the psychic power given to me by my Great, Great, Great, Great Grandmother (Hilda the Great), my guess is that you haven't build all the libs yet. Did you build the lib workspace before you tried building the engine?
08/13/2001 (7:50 pm)
Error executing link.exe. Here is the error i get when i try to batch build the v12 engine.dsw and the tools.dsw. Please help
Please give us more information. "Error executing link.exe" does not give us any details about the error.
Although, using the psychic power given to me by my Great, Great, Great, Great Grandmother (Hilda the Great), my guess is that you haven't build all the libs yet. Did you build the lib workspace before you tried building the engine?
#12
08/13/2001 (10:07 pm)
I got mail from Bryan with a copy of the error output, he's getting "link" errors because he doesn't have NASM installed.
Torque Owner David Stewart Zink
The most obvious of which is changing the "size()" method of the vector class to return a signed number instead of unsigned.