#1301 posted by necros on 2014/02/08 05:23:57
no dice, neither from adding virtual or override. :(
From what I've read, once you put virtual on a method, everything from that point forward will always be virtual, ie: behave as expected of a polymorphic object and properly call child class methods if held in a base class container.
#1302 posted by ericw on 2014/02/08 06:18:30
ah, you're right - sorry for the bad advice! the setup of evaluatePhysics() looks fine to me then.
all I can think of is generic debugging advice.. like, stick a:
printf("inside Particle::evaluatePhysics()\n");
at the first line of evaluatePhysics(). double check the particle object you're calling ->evaluatePhysics() on is not NULL. is it possible Game::FrameTime() is dereferencing a null pointer?
it should be possible to get a debugger to break when a null pointer dereference happens, so you can look at the call stack and ideally see exactly where the problem is. which IDE/environment are you using?
Test Case
#1303 posted by Preach on 2014/02/08 10:04:30
Here's my very reduced test case
http://ideone.com/u1scWv
I actually put an implementation in my base class but it's easy to check that it works when it's pure virtual. Anyway, it's all got the same syntax and setup as your code above, so there's a detail wrong somewhere.
Have you tried putting a dummy evaluatePhysics function in PhysObject for debugging purposes. Just a quick one-liner that maybe logs a message. It would be a quick way to test if it is the "pure virtual" function which is causing the null pointer dereference.
#1304 posted by necros on 2014/02/08 16:28:54
Nothing changes when I implement evaluatePhysics in PhysObject, so something else must be going wrong here.
debug on particle object: http://tinypic.com/r/ibctq9/8
There's a __vfptr member at 0xCDCDCDCD?
Here's the entire Particle class:
http://pastebin.com/jmtfPHs3
static void drawParticles() is called each frame which in turn calls this->evaluatePhysics() on any living particle.
Self.items Bugs
#1305 posted by Qmaster on 2014/02/08 19:37:49
Can anyone explain to me what the limit is on numbers that I can store in self.items, and how it works? I've been having some very odd bugs with my mod. I have 16 different weapons, but for some reason I'm getting wierd errors where certain weapons are already owned, getting ammo gives the weapon, etc. etc. I'm thinking that perhaps there is a limit on how high the number can be for IT_<WEAPON NAME HERE> in the defs.qc. Is 16777216 too high a number to even fit in the float variable self.items?
I understand that certain numbers are assigned in a bitwise fashion for the correct HUD art to display, but I think I'm misunderstanding how it all works.
Append To Previous Post...
#1306 posted by necros on 2014/02/08 19:42:44
cleaned up the code I posted above:
http://pastebin.com/hAXRXryT
Qmaster
#1307 posted by necros on 2014/02/08 19:44:43
highest number you can use for any number in qc: 8388608
#1308 posted by necros on 2014/02/08 19:45:06
highest flag you can use, sorry. :(
Trial And Error With IT_ Numbers
#1309 posted by Qmaster on 2014/02/08 20:31:11
Still hammering out (inside joke/pun!) the problems with IT_ numbers (1,2,4,8,16,32,etc.,4096,8192,etc). Apparently there is some engine code to handle the numbers stored in self.items, because otherwise picking up one item with a completely different touch function from another wouldn't still play that item's pickup sound. Apparently the engine is looking for a sum??(help!?) of the items contained??
#1310 posted by necros on 2014/02/08 20:50:20
so the way items works is that each IT_ value corresponds to a bit.
in binary,
1 is 0000000000001
2 is 0000000000010
4 is 0000000000100
etc...
storing items this way is a compact way of storing a bunch of yes/no settings in one spot.
if you do items = items | 4 you are essentially setting bit #3 to on. if it was already on, nothing happens.
so if you have multiple items stored on items, if you were to print it, you might see '7'
but actually what it is is: 0000000000111
so it means bits 1, 2 and 3 are 'on', in other words if you had:
IT_GUN1 = 1
IT_GUN2 = 2
IT_GUN3 = 4
it would mean you had all 3 guns in your inventory.
@necros
#1311 posted by ericw on 2014/02/08 20:52:44
I think i see the problem, it's cause by allocating memory with malloc, and then copying the particle in.
Here's a reduced test case that segfaults on the line particle->evaluatePhysics();:
http://pastebin.com/WB7iVHP1
I can't find a great explanation of why this is illegal. there is some stuff here: http://www.drdobbs.com/cpp/calling-constructors-with-placement-new/232901023?pgno=1
To fix it, I'd replace this:
Particle* Particle::pool = (Particle*)malloc(sizeof(Particle) * Particle::MAX_PARTICLES);
with an std::vector<Particle> Particle::pool;.
generally, you should avoid malloc in a c++ program and use new/delete, and the STL containers.
hope this helps :)
Thanks!
#1312 posted by necros on 2014/02/08 21:51:35
That seems to be exactly what the problem was! I had used a static array because I planned to never grow it in size, but didn't know that it had trouble handling polymorphic stuff. Guess I shall stay away from malloc from now on.
@necros
#1313 posted by Qmaster on 2014/02/08 22:17:50
That makes so much sense now! Thank you! So this means that a standard quake integer (read that the float is floored) would initiate to 0000000000000000000000000000000 (32 0's) since it's 32bit, right? So I could have a total of 32 weapons then right?
Qmaster
#1314 posted by Preach on 2014/02/08 22:30:41
Unfortunately not. QC doesn't let you use integers, but floats. A 32 bit float only dedicates 24 bits to "places" in the number, the rest tell you the sign and the "scale" of the number. Basically when the number is large enough a float can't store integers accurately - the largest whole number that can be safely stored without rounding is 16777215. That's why necros gave 8388608 as the maximum size.
It is possible to use the non-place bits in a floating point value for more flags, but it's really incredibly fiddly. Better to just add another field to the entity and store the extra flags there.
re: pickup sounds. These are all specified in items.qc - the sound is based on the classname of the entity you touch.
16777216
#1315 posted by Qmaster on 2014/02/08 22:51:51
http://dev.xonotic.org/projects/3/wiki/Introduction_to_QuakeC
float
This is the basic numeric type in QuakeC. It represents the standard 32bit floating point type as known from C. It has 23 bits of mantissa, 8 bits of exponent, and one sign bit. The numeric range goes from about 1.175e-38 to about 3.403e+38, and the number of significant decimal digits is about six.
As float has 23 bits of mantissa, it can also be used to safely represent integers in the range from -16777216 to 16777216. 16777217 is the first integer float can not represent.
Oh Didnt See @Preach's Post
#1316 posted by Qmaster on 2014/02/08 22:58:20
So that explains why I've had so many issues with the weapon assigned to the last bit slot of 16777216. Good to know that 8388608 is max. Phew, adding more weapons is gonna be a bit tricky then.
#1317 posted by necros on 2014/02/08 23:54:32
the way floating point numbers are stored is actually pretty cool. it allows for a huge amount of scaling at the expense of precision.
!
#1318 posted by Qmaster on 2014/02/19 04:07:34
BUMP!!
Can we please sticky this thread next to Mapping Help? I come here often to read up on awesome stuff going on in QC Land but I keep having to dig down in All Threads.
#1319 posted by necros on 2014/03/23 03:51:21
is there a reason why C++ compilers are so unhelpful?
the language is nice and having access to the heap and more control over what goes on the stack is great but tracking down some bugs or even mistyped things can be such a hassle.
Clang
#1320 posted by Preach on 2014/03/23 06:44:33
I've not used it myself, but one of the touted features of the clang compiler is superior error message delivery:
http://clang.llvm.org/diagnostics.html
Might be worth a punt...
Hah
The problem with C++ error messages is (nested) templates. This makes the error messages very long and basically unreadable. The Xcode IDE is quite helpful here because it allows you to click on the separate lines of a template error and highlight their occurrence in the source files.
Other than that, I remember reading a trick to simplify the error messages in a C++ book. I can look it up if you're interested.
Preach, maybe clang has better error messages than others, but they're still hard to understand when there are templates involved ;-)
#1322 posted by mwh on 2014/03/23 10:31:34
#1323 posted by JneeraZ on 2014/03/23 14:16:55
#1324 posted by necros on 2014/03/23 16:36:59
lol willem, yeah, i feel like that sometimes. :)
as for using another compiler, i have no idea how to change it since i'm using visual studio 2012... i assume i'm just using microsoft compilers of some kind.
Cpp
#1325 posted by necros on 2014/03/23 21:09:57
to give an example, at one point i started getting an error saying NULL was an undefined variable. and then suddenly it went away and I have no idea what caused that to happen.
|