C++ bug? Or am I just crap?


#1

Okay, guys - take a look at this problem I’m having with C++ & MS Visual C++ 6.0…

  1. Lets say you made a simple structure. It contains afew integers and a DirectDraw7 surface pointer…

  2. You name this structure “Struct_1”.

  3. You then make an array of “Struct_1” structures. Say…maybe…50 elements. The name for this array is “array[50]”.

  4. Now then, you also have another structure - but a totally different one! It comes from an entirely different template. And you also made an arrary of it…say 10,000 elements. It also contains integers & one DD7-surface pointer…

  5. During runtime you write code to change one of Struct_1’s integers like so…

        array[0].first_integer = 1;
    

…and you know for a fact that is the exact code - because you wrote it!

  1. However, at runtime - it doesn’t do this! It insted changes a variable in one of the structure-elements in the other array! A COMPLETELY DIFFERENT ARRAY!!! And the vaule in “array[0].first_integer” is 0…

  2. Now lets say you then checked the code for any possible incorrect pointer-assignments etc and found none!

…how is this possible? I’ve checked my source code for all assignments regarding these two different arrays and they NEVER asigned values to each other.

This has really got me stumped!:banghead:


#2

Its alright, guys - I’ve only just figured it out! I feel really stupid now…:blush:

Remember I said the array size was 50? Well, I was using an integer as the index value - THE WRONG BLOODY INTEGER VARIABLE!!!

I had the assignment after a FOR loop to determine which was the first, avaliable structure for use…like so!

int d = -1;

for( int i = 0; i < 50; i++ )
{
if( array[i].in_use == NOT_IN_USE )
{
d = i;
i = 51;
}

if( d == -1 )
return;
else
{
array[i].in_use = 1;
// etc, etc
}

…do you see? I used the FOR loop counter( “i” ) insted of the variable “d”…so I was trying to access array element “51” in an array size of “0” to “49”…

I’ve been stuck with this error for over a week, now…I FEEL LIKE A RIGHT PRAT!!!:banghead:

Sorry for wasting your time, and CGTalk’s server space…:blush:


#3

Cool, these are they types of problems I like to see. Ones that are solved before I have to burn up my brain juice :smiley:

Lots of good posts in this section Boone hopefully it will take off, what are you working on at the moment?


#4

Re: Frank Dodd.

I’m working on a “Forgotten Worlds” Clone…after fixing the “bug”, I’ve just got to sort out some reasonable way for bullet-collision…then its just tarting up!

RS3D? Do you by any chance use RealSoft3D? Just curious…:slight_smile:


#5

Yep Realsoft 3D, I’ve been using it for many years now hopefully the new version will be having improved games modelling support.

“Forgotten Worlds”, I assume that’s the old 2D sideway scroller from Sega. Cool sounds like fun :slight_smile: do you have all the graphics and sound done?


#6

Re: Frank Dodd.

RealSoft3D rocks!:love:

Yep, it was an awesome arcade game by CAPCOM and later reprogrammed for the Sega Genesis. And everyother platform at the time!

The “Meat and Potatoes” of the game is done, but I’ve still some more to do in the backgrounds, sprites, music & sound departments…:hmm:

Thankfully its all straight forward from here…:applause:


#7

Cool, good luck with it it will be nice to see some screenshots as they become available. :thumbsup:


#8

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.