#### Archived

This topic is now archived and is closed to further replies.

# the walls of sanity are crashing down upon me.

This topic is 5505 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m writing my program, everything is going good. Got my translucent blitting objects going on with pixel collisions. Got my loading routines all working good. Everything looks perfect. Now all the sudden it is crashing all the time! Whats worse is, the crashes are inconsistent. It is pissing me off big time! I have backed up my code and I am sitting here cutting huge chunks out of it to try and isolate the bug but nothing is working! Im on the verge of having to restart my project from scratch and I cant even figure out why!!! Arrghh! - Twisted Matrix

##### Share on other sites
quote:
Original post by TwistedMatrix
Now all the sudden it is crashing all the time! Whats worse is, the crashes are inconsistent.

That probably means you are doing something with memory that doesn''t belong to you. Look out for things like this:

- overrunning array bounds;
- deleting or freeing memory more than once;
- dereferencing wild pointers;
- dereferencing null pointers.
quote:

Im on the verge of having to restart my project from scratch and I cant even figure out why!!! Arrghh!

Let that be a lesson to you to develop incrementally, take back-ups and write automated tests that tell you when something breaks.

##### Share on other sites
i think your write. I know this is some kind of pointer problem but I can't find it. I've done my best to isolate some consistent results in this function...
/*  process_lemming_actions() *  cur is the current lemming, max is the lemming count */void process_lemming_actions(struct lemming *lemming, int cur, int max){   int i,d;//,x,y;   //struct lemming c;      if (lemming[cur].action==WALKING) {     /* check the current lemming for collisions against blockers */     for (i=0;i< max;i++) {       if (lemming.action== BLOCKING) {         if ((lemming[i].x < lemming[cur].x+ SPRITE_W) &&             (lemming[i].y < lemming[cur].y+ SPRITE_H) &&             (lemming[i].x+SPRITE_W >= lemming[cur].x) &&             (lemming[i].y+SPRITE_H >= lemming[cur].y)) {           /* if they are colliding, then change direction */           d=~lemming[cur].direction;           lemming[cur].direction= d;           /* and push the current lemming out of the collision              (so they dont endlessly turn left and right in place) */           d=lemming[i].x;           if (lemming[cur].x> d) { lemming[cur].x= d+SPRITE_W; }           else                   { lemming[cur].x= d-SPRITE_W; }         }       }     }     move_lemming(&lemming[cur]);   }   /* if a lemming is a "digger" then start choping away pixels */   for (i=0;i< max;i++) {     if (lemming[i].action==DIGGING) {//       d=lemming[i].x;//       a=lemming[i].y;a+=SPRITE_H;//       for (x=d-1; x//         putpixel(scene,x,a, mask);//       }//       d=lemming[i].x+rnd(4);//       for (x=d-1; x//         putpixel(scene,x,lemming[i].y+SPRITE_H+1, mask);//       }//       d=lemming[i].x+rnd(8);//       for (x=d-1; x//         putpixel(scene,x,lemming[i].y+SPRITE_H+2, mask);//       }     }   }}END_OF_FUNCTION(process_lemming_actions);

as you can see, most of it is still cut out.
as the function sits, it works correctly every time I run it. however, changle the first line to: int i,d,x,y;
and It malfunctions. additionally, if I Un-remark the second line, it begins to work again.

somthing really weird is going on because these added variables do absolutly nothing. They are not used anywhere else in the program.

- Twisted Matrix

[edited by - TwistedMatrix on November 20, 2002 12:23:26 PM]

##### Share on other sites
This line:

if (lemming.action== BLOCKING) {

needs to be fixed. Should most likely be lemming [ i ].action.

Also,

d=~lemming[cur].direction;

Are you sure you want a bitwise not on there?

If lemming[cur].direction = 1 then d will probably equal something like 65534.

Perhaps change that to lemming[cur].direction *= -1;

[edited by - Melraidin on November 20, 2002 12:33:53 PM]

##### Share on other sites
for some reasont the forum cut it out. the line is actually

if (lemming[ i ].action== BLOCKING) {

and also, yes the "Binary NOT" was intentional. Im still a newbie, so if you have any other ideas for doing a quick XOR type effect on (eg on; off; on; off, ect)

this is driving me crazy.

##### Share on other sites
There is a better solution to your if''s wich produces smaller code. Programmer_One told me this solution once. I guess all your actions are #defined or constants. Why don''t you use an switch to check this? This will produce waay faster and smaller code:

  // Made them 1000 or higher to make it look cool#define MOVING 1000#define BLOCKING 1001#define CHOPPING 1002#define WHATEVER 1003// Do Lemming shite herefor (iIndex = 0; iIndex < MAX_LEMS; iIndex++){   switch (Lemming[iIndex])   {      case MOVING: Move_Lemming(); break;      case BLOCKING: Block_Lemming(); break;      case CHOPPING: Chop_Lemming(); break;      case WHATEVER: Whatever(); break;      default: break; // Should shouldn''t come here   } // END switch} // END for

This solution will be easier to read, and will be much smaller and so, it will be easier to debug since you don''t have large pieces of code where you could make a mistake.

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.

My Site

• ### Forum Statistics

• Total Topics
628728
• Total Posts
2984419

• 25
• 11
• 10
• 16
• 14