www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/08/13:01:41

Message-ID: <20000408155631.7966.qmail@hotmail.com>
X-Originating-IP: [195.100.144.172]
From: "Fredrik Olsson" <fredrik0725 AT hotmail DOT com>
To: dj AT delorie DOT com
Subject: bug?
Date: Sat, 08 Apr 2000 08:56:31 PDT
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

Hi there all djgpp'ers !

I have 2 problems with my program,
and I've spent more than 30 hours debugging it.
Still I can't find anything wrong
in my code.. so I'm hoping for some help
from you...

The only thing I can think of after debugging
it is somekind of lack of base memory
(the first 640k, don't really know what its called),
I think that's where local variables are stored?
So that somehow the function called uses the same
memory as the previous function, and overwrites "int i".

But if this is so, I dont have a clue on what to do.
I've enlarged the minimum stack space for cc1.exe and
cc1plus.exe to 512k resp. 1024k - using stubedit,
but that didn't make it..

Thank you for taking your time.


==================================================
Problem 1:
When u_RemoveFromSolid (int id) is called from
u_AddToSpawnList (int id), the variable "int i" is changed.



- I have debugged the code and I found that
"int i" is changed when calling u_RemoveFromSolid()
from u_AddToSpawnList(), on that exact line.

Cause is now narrowed down to something in u_RemoveFromSolid();

Testing:

1. Added return; in begining of u_RemoveFromSolid() and "int i" was not
changed.

2. Locked "int i" in u_AddToSpawnlist() and "int i" was not changed.

3. Included "units.h" for T_SOLID flag and "int i" changed from 47k to 225
  after u_RemoveFromSolid ().
  (Stupid miss of me, T_SOLID const flag was not set before)

4. including "sv_u.h" to all files calling functions within "sv_u.c"
  -unsuccessful ("int i" is still changed)



Probable causes:

Something is overflowing - probably in u_RemoveFromPhysics()?

Some kind of segmentation fault when
u_RemoveFromSolid() were run from u_AddToSpawnList()?


Something in u_RemoveFromSolid() was poking in memory and got to "int i"?


Here is the code:

//*****************************************************************************************
//                                       U_REMOVEFROMSOLID

void u_RemoveFromSolid (int id) {
int ai=0, removed;


for (ai=0;ai<MAXUNITS;ai++)
if (solid[ai] == id)
{

       // remove unit
       solid[ai] = 0;
       unit[id]->tables = unit[id]->tables & ~T_SOLID;
       removed = ai;


       // resort list

       for (i=MAXUNITS-1;i>removed;i--)
        if (solid[i] != 0) {
         solid[removed] = solid[i];
         solid[i] = 0;
         return;
        }


       return;

}

// this should not happen


Sys_Error ("sv_u.c; u_RemoveFromSolid(); - unit[%d]->type = %d  Requested
unit not in list!", id, unit[id]->type);


}



//*****************************************************************************************
//                                       U_ADDTOSPAWNLIST

void u_AddToSpawnList (int id) {
int i;

//LOCK_VARIABLE (i);

// sort in spawnitem in cue
for (i=0; i<MAXUNITS; i++)

if (spawn_list[i]->wait > unit[id]->wait || i == spawn_list_count)
{


// remove unit from tables if any

if (unit[id]->tables & T_SOLID){

  // at this time i == 0
  // after the next line is run "int i" is changed.

  u_RemoveFromSolid (id);

  // at this time i == 427272

}

if (unit[id]->tables & T_PHYSICS){
  u_RemoveFromPhysics (id);
}



// make room for new spawnitem

if (spawn_list_count > 0)
  memcpy (spawn_list[i+1], spawn_list[i], sizeof(struct u) *
(spawn_list_count - i));


// move spawnitem to list

memcpy (unit[0], unit[id], sizeof(struct u));

free_unit (id);

spawn_list_count ++;


return;

}





Sys_Error ("sv_u.c; u_AddToSpawnList(); - Could not add unit %d to
spawn_list! (type = %d)", id, unit[id]->type);
}


==================================================
2:
--Could not debug some variables, "not availuable"
-still they can hold values:

int a[10], b;

b = 22;
a[0] = b;

(when evaluating "int a" it is 22)



Thanks for your time!
/Fredrik Olsson, Fredrik0725 AT hotmail DOT com
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019