QuantiCode games

Zero Ballistics, Full Metal Soccer

Skip to content

Obvious bug in the code -- but how to fix it correctly?

Post any problems related to the beta version of Zero Ballistics

Moderators: Michael, Bernhard, Christian

Obvious bug in the code -- but how to fix it correctly?

Postby b3nn0 on 18 Mar 2012, 23:14

Hey there,
I have checked out the ZB code from SVN and am currently trying to get it to run (and do some modifications)
There is a bug in TerrainData.cpp:
Code: Select all
    for (int i=0; i<4; ++i)
    {
        for (int j=0; j<4; ++j)
        {
            x_interpol [i] += h_base[j-1 + (i-1)*width_]*cx[j];
            xd_interpol[i] += h_base[j-1 + (i-1)*width_]*cxd[j];
        }
    }

which is obviousely wrong (for i=0 and j=0, this yields a negative index into the h_base array).
However, I'm not very familiar with the code. So could you point me into the right direction to fix this? I'd really like to do some development on that code :)

EDIT: Okay, looking at the code a bit more, it actually seems correct (but maybe not the most command semantic).
Anyway, the game crashes for me at that code.
I tried to replace it with this:
Code: Select all
            x_interpol[i]  = height_data_[hbase_loc + (j-1 + (i-1)*width_)];
            xd_interpol[i] = height_data_[hbase_loc + (j-1 + (i-1)*width_)];

where hbase_loc is int hbase_loc = x_int + z_int * width_;.
It doesn't crash any more, however, it still doesn't work correctly. The heightmap seems to be messed up resulting in the tank either not driving at all or jumping through the map :/

edit 2: nvm.. I forgot the * cx[j]. It seems to work correctly with that now.
b3nn0
 
Posts: 12
Joined: 12 Jan 2011, 13:18
Location: Germany

Re: Obvious bug in the code -- but how to fix it correctly?

Postby Freder on 31 Mar 2012, 13:07

I had the same problem, but I came up with a different solution. I have no idea why yours still produced a SegFault for me... I just make sure that the index is > 0 in line 235:
Code: Select all
    for (int i=0; i<4; ++i)
    {
        for (int j=0; j<4; ++j)
        {
            int index = j-1 + (i-1) * width_;
            if (index < 0) {
                index = 0;
            }
            x_interpol [i] += h_base[index]*cx[j];
            xd_interpol[i] += h_base[index]*cxd[j];
        }
    }

I seem to have a different problem, all the trees are invisible for some reason, and only appear when hit. Did you have similar issues?
Freder
 
Posts: 5
Joined: 29 Mar 2012, 19:35
Location: Poland

Re: Obvious bug in the code -- but how to fix it correctly?

Postby b3nn0 on 04 Apr 2012, 10:29

Freder wrote:I had the same problem, but I came up with a different solution. I have no idea why yours still produced a SegFault for me... I just make sure that the index is > 0 in line 235:
Code: Select all
    for (int i=0; i<4; ++i)
    {
        for (int j=0; j<4; ++j)
        {
            int index = j-1 + (i-1) * width_;
            if (index < 0) {
                index = 0;
            }
            x_interpol [i] += h_base[index]*cx[j];
            xd_interpol[i] += h_base[index]*cxd[j];
        }
    }

I seem to have a different problem, all the trees are invisible for some reason, and only appear when hit. Did you have similar issues?


Hey.
I got my code to work. I simply forgot the *cx[j]. WIth that it worked perfectly.
About your solution: I'm not sure if this still works correctly. Well, I'm pretty sure it doesn't. Don't you get problems with your heightmap? (e.g. the tank driving not correctly but jumping from time to time and stuff like that?)

About the trees: Not sure. I did many changes to the code to port it to more recent library versions (newer version of boost-filesystem, new version of OSG, etc).

I had the problem once after the new OSG customizations, but it was a mistake by myself and I could easily fix it.

Anyway.. I have - as I said - made many customizations to the code to improve it. I have that code online in a private SVN (talked to Quanticode about forking or SVN write-access to their repository but diddn't get a useful response yet).
If you want, you can PM me and I give you access to my code and you try that out. I think it should work better than the original one. Especially on more modern systems with more recent libraries.
And it also works on 64 bit (but I diddn't change anything for that. It just worked).
b3nn0
 
Posts: 12
Joined: 12 Jan 2011, 13:18
Location: Germany

Re: Obvious bug in the code -- but how to fix it correctly?

Postby Michael on 09 Apr 2012, 12:01

Hi b3nn0

you should have access to the SVN and Wiki (if you would like to add smth. to the build instructions) on sourceforge by now. feel free to commit your code changes and thanks for your effort in advance!

kind regards,
Michael
Michael
Developer
 
Posts: 204
Joined: 29 Mar 2008, 17:19

Re: Obvious bug in the code -- but how to fix it correctly?

Postby b3nn0 on 10 Apr 2012, 13:33

Thank you, Michael.

I'm currently still on vacation but will be back in a few days.
b3nn0
 
Posts: 12
Joined: 12 Jan 2011, 13:18
Location: Germany


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest


cron