Thread: Segmentation Fault

  1. #1
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100

    Segmentation Fault

    i figured i'd start another thread because it's a new question.

    Array of objects;
    Code:
    bool Bullet::move(){
        if(loc.X > BLEFT && loc.X < BRIGHT && loc.Y > BTOP && loc.Y < BBOTTOM){
            switch (dir){
                case UP:
                    loc.Y--;
                    break;
                case DOWN:
                    loc.Y++;
                    break;
                case LEFT:
                    loc.X--;
                    break;
                case RIGHT:
                    loc.X++;
                    break;
                }
                this->drawBullet();
                return true;
            }
         else {
                this->outBound();
                return false;
            }
        }
    
    ..........
    
    int main { 
       .........
       Bullet *bull[4];
        bull[0]=new Bullet(20,10,RIGHT);
        bull[1]=new Bullet(20,10,LEFT);
        bull[2]=new Bullet(20,10,DOWN);
        bull[3]=new Bullet(20,20,UP);
        while(true){
            for(int i=0; i < 4; i++){
                if(bull[i] != 0)
                    thePlay->drawPlayer();
                    if(!bull[i]->move()){
                        delete bull[i];
                        bull[i]= 0;
                 }
               ........
              }
    It worked before, but now it doesn't!
    Sorry, but i'm a Code::Blocks man now.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Where's your curly-braces keeping everything in the if(bull[i] != 0) statement together?

    (Edit: Yes I realize it should grammatically be where are. Don't care.)
    Last edited by tabstop; 06-04-2008 at 07:40 PM.

  3. #3
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    damnit...
    Sorry, but i'm a Code::Blocks man now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault problem
    By odedbobi in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2008, 03:36 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM