Results 1 to 4 of 4

Thread: illegal operation during execution

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2001
    Posts
    13

    illegal operation during execution

    hello,

    i write a c program that draws a fractal in a Dev-C++ compiler. it is fully compiled but when executed an illegal operation message pops up. also, the display screen is colorless.
    does anyone know what is happening? please let me know.
    here is the untested code, i would appreciate any help. thanks!

    godach

    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <gl\gl.h>
    #include <gl\glut.h>
    #define PI 3.14159
    #define FOR(i,a,b) for(i=a;i<b;i++)

    typedef struct{ /*A new structure that defines the coordinates of a point.*/
    double x;
    double y; /*Define z may be useful but not required in this project.*/
    }coordinates;

    coordinates pt[8];
    coordinates bb[4]={0.,0.,
    1.,0.,
    1.,1.,
    0.,1.}; /*Define the coordinates of the base square*/

    void transform(double ro, /*Performs 2-by-2 similitude (a case of affine transformation).*/
    double sc, /*Accepts rotation (ro), scale factor (sc), translation coordinates(tr),*/
    coordinates tr, /*and the coordinates of the point to be transformed (input),*/
    coordinates input[],/*and returns the transformed coordinates to the calling function.*/
    coordinates output[]){
    int i;
    output[i].x=sc*cos(ro)*input[i].x-sc*sin(ro)*input[i].y+tr.x;
    output[i].y=sc*sin(ro)*input[i].x+sc*cos(ro)*input[i].y+tr.y;
    }

    int even(int num){
    int ans;
    ans=((num%2)==0);
    return(ans);
    }

    void display (void){
    int aa,cc=0;
    int po=20;
    int pp=1;
    int gg=0;
    int ii=0;
    coordinates tt={0.,1.};
    double z[1]={-5.};
    double rr=0.;
    double ss=1/cos(0.);

    glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(0.,0.,0.,0.);
    glMatrixMode(GL_MODELVIEW);


    FOR(aa,0,po){ /*A function is needed to perform population calculation*/
    cc+=1;
    if(even(cc))
    FOR(ii,0,4){
    transform(PI-rr,ss,tt,bb,pt);
    }
    else
    FOR(ii,0,4){

    transform(rr,ss,tt,bb,pt);
    }

    if(cc==pp){
    cc=0;
    gg+=1;
    pp=pow(2,gg);
    rr+=PI/6;
    ss=ss*1/2/cos(rr);
    }
    FOR(ii,0,4){
    glBegin(GL_LINES);
    glColor3f((GLfloat)0.,(GLfloat)0.,(GLfloat)1.);
    glVertex3f(pt[ii].x,pt[ii].y,z[0]);
    glEnd();
    }
    }


    glutSwapBuffers();
    }

    void init(void)
    {

    glClearColor(0.0f ,0.0f ,0.0f ,0.0f);
    glColor3f(0.0f,0.0f,1.0f);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,(GLfloat)250/(GLfloat)250,0.1f,100.0f);
    }
    void idle(void){glutPostRedisplay();}

    int main(int argc, char *argv[])
    {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(100,100);
    glutCreateWindow("Two Dimensional Fractal Broccoli");
    init();
    glutDisplayFunc(display);
    glutIdleFunc(idle);
    glutMainLoop();
    return 0;
    }


    godach

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2001
    Location
    London UK
    Posts
    195

    Re: illegal operation during execution

    Your code is pretty non standard and hard to read. For example:
    else
    FOR(ii,0,4){

    transform(rr,ss,tt,bb,pt);
    }

    You should not include windows.h and gl.h if you are using GLUT under windows.

    If you debug your code with gdb will it tell you that the crash is in the transform function. Take another look before I write the answer:

    void transform(double ro, /*Performs 2-by-2 similitude (a case of affine transformation).*/
    double sc, /*Accepts rotation (ro), scale factor (sc), translation coordinates(tr),*/
    coordinates tr, /*and the coordinates of the point to be transformed (input),*/
    coordinates input[],/*and returns the transformed coordinates to the calling function.*/
    coordinates output[]) {
    int i;
    output[i].x=sc*cos(ro)*input[i].x-sc*sin(ro)*input[i].y+tr.x;
    output[i].y=sc*sin(ro)*input[i].x+sc*cos(ro)*input[i].y+tr.y;
    }

    Right, i is used before assigned a value.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2001
    Posts
    13

    Re: illegal operation during execution

    hi mango,

    i replaced i with a new variable and removed gl.h and windows.h but the illegal operation message is still up. can you give me more details as to how to deal with it?

    thanks!

  4. #4
    Guest

    Re: illegal operation during execution

    Wow, that code is bad. Clean it up a little, and you will find the error.
    It really is a mess now!
    Use proper statemnts, that for call is BAD!

Similar Threads

  1. Illegal Operation
    By Raven4803 in forum OpenGL: User Software
    Replies: 1
    Last Post: 03-11-2003, 12:01 PM
  2. Replies: 3
    Last Post: 08-08-2002, 12:40 AM
  3. Illegal operation.. or something
    By in forum OpenGL: User Software
    Replies: 2
    Last Post: 06-30-2001, 10:40 AM
  4. Illegal Operation - NVOPENGL.DLL
    By in forum OpenGL: User Software
    Replies: 1
    Last Post: 02-24-2001, 04:53 PM
  5. Is this illegal?
    By Mongoose in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 09-28-2000, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean