www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/02/10:51:51

From: "Roger Lindström" <kjell DOT lindstrom AT sundsvall DOT mail DOT telia DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: program crash
Date: Sat, 2 Jan 1999 16:45:46 +0100
Organization: Telia Internet Services
Lines: 65
Message-ID: <368e3f41.0@d2o30.telia.com>
NNTP-Posting-Host: d2o30.telia.com
X-Newsreader: Microsoft Outlook Express 4.72.2106.4
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
X-NNTP-Posting-Host: t3o30p29.telia.com
X-Complaints-To: abuse AT internet DOT telia DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Help!! My program crashes if antal ( look at row **** This one ****) is over
12000. Can someone tell me wahts wrong.

#include <stdio.h>
#include <math.h>
#include "allegro.h"

class Star {
private:
    int posX,posY;
    int speedX,speedY;
    int color;
public:
    void set(int x,int y,int col,int size);
    void operator ++ (int);
    void clear();
    void putStar();
};

void Star::set(int x,int y,int col,int size) {
    posX=x<<16; posY=y<<16; color=col;
    double speed=random()%size;
    double vinkel=random();
    speedX=speed*cos(vinkel);
    speedY=speed*sin(vinkel);
}
void Star::operator++ (int) {
    clear();
    posX+=speedX; posY+=speedY;
    putStar();
    speedX-=speedX/70; speedY-=speedY/70;
    speedY+=450;
}
void Star::clear()   { putpixel(screen,posX>>16,posY>>16,0); }
void Star::putStar() { putpixel(screen,posX>>16,posY>>16,color); }

int main()
{
   allegro_init();
   install_keyboard();
   set_color_depth(32);
   if(set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0) {
       set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
       printf("Unable to select a 1024x768 32 bit screen mode\n");
       return 0;
   }

    clear_keybuf();
    int key=0;
    while (key!=27) {
#define antal 1000 // **** This one ****
        Star lista[antal];
        for(int i=0; i<antal; i++) lista[i].set(500,350,random(),0x40000);
        for(int a=0; a<250; a++) {
            vsync();
            for(int i=0; i<antal; i++)  lista[i]++;
        }
    for(int i=0; i<antal; i++) lista[i].clear();
    key=readkey()&0xff;
    }
    return 0;
}



- Raw text -


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