C分段故障的方法

时间:2017-04-07 07:51:33

标签: c compilation segmentation-fault

我正在尝试使用setup_diamond()draw_game()函数,并且我一直遇到分段错误。我根本不知道为什么我会遇到这个错误,据我所知,所有内容都被正确存储并初始化。

//Function for preparing the diamonds
void setup_diamond() {
    //For loop, the size of the number of max diamonds
    for (int i = 0; i < MAX_BD; i++){
        //Creates an array which stores the values for the diamond x values
        rand_x_value[i] = rand() % (screen_width()-BD_WIDTH);
        //Creates 10 big diamonds based on the rand angle
        Bdiamond[i] = sprite_create( rand_x_value[i], 3, BD_WIDTH, BD_HEIGHT, Bdiamond_image );
        //Creates a random angle which is saved in an array
        randAngle[i] = rand() % 360;
        //Set's the diamonds speeds to 0.1
        sprite_turn_to (Bdiamond[i], 0.1, 0);
        //Points the diamond in the random direction saved in the array
        sprite_turn (Bdiamond[i], randAngle[i] );
        //Draws the diamond
        sprite_draw (Bdiamond[i] );
        //Creates 20 medium sized diamonds
        for (int q = 0; q <= 20; q++){
        Ldiamond[q] = sprite_create(-5, -5, LD_HEIGHT , LD_HEIGHT, Ldiamond_image);
        }
        //Creates 40 small diamonds
        for (int k = 0; k <= 40; k++){
        Mdiamond[k] = sprite_create(-3, -3, MD_WIDTH , MD_HEIGHT, Mdiamond_image);
        }

    }

}

void draw_game() {
    clear_screen();
    draw_border();
    sprite_draw ( ship );

    for (int i = 0; i < MAX_BD; i++ ) {
        sprite_draw(Bdiamond[i] );
    }

    for( int i = 0; i <= MAX_BULLET; i++){
        sprite_step(bullet[i]);
        sprite_draw(bullet[i]);
    }
    //Creates 20 medium diamonds at an offscreen position ready for use when diamonds are split
    for( int k = 0; k <= MAX_MD; k++){
        sprite_step(Mdiamond[k]);
        sprite_draw(Mdiamond[k]);
    }
        //Creates 40 small diamonds off screen
    for( int q = 0; q <= MAX_LD; q++){
        sprite_step(Ldiamond[q]);
        sprite_draw(Ldiamond[q]);
    }
}

我的源文件夹here

有一个链接

它包含代码(在&#39; c&#39;)和我的库文件夹。我正在使用Cygwin进行编译。

0 个答案:

没有答案