Click here to Skip to main content
15,867,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am writing an openGL program. my code is here:
C++
GLint Steps = 4;              
GLint RaysPerStep = 8;

void randcolor()
{
    GLint a,b,c;
    a = rand()%101;
    b = rand()%101;
    c = rand()%101;
    X[0] = (GLfloat)a/100.0;
    X[1] = (GLfloat)b/100.0;
    X[2] = (GLfloat)c/100.0;
}

void colours(int id)
{
    flag = id;
    if (flag == 1)
        randcolor();
    glutPostRedisplay();
}

void flow(int id)
{
    RaysPerStep = id;
    glutPostRedisplay();
}

void level(int id)
{
    Steps = id;
    glutPostRedisplay();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(1324,750);
    glutInitWindowPosition(0,0);
    glutCreateWindow("Flowing Fountain");
    glEnable(GL_DEPTH_TEST);
    glClearColor(0,0,100,1.0);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_BLEND);
    glLineWidth(2.0);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    InitFountain();
    CreateList();
    glutDisplayFunc(Dis);
    glutReshapeFunc(Reshape);
    glutKeyboardFunc(NormalKey);
    
    int sub_menu = glutCreateMenu(colours);
    glutAddMenuEntry("RANDOM",1);
    glutAddMenuEntry("GREEN",2);
    glutAddMenuEntry("BLUE",3);
    
    int sub_menu2 = glutCreateMenu(flow);
    glutAddMenuEntry("LOW",8);
    glutAddMenuEntry("MEDIUM",10);
    glutAddMenuEntry("HIGH",20);
    
    int sub_menu3 = glutCreateMenu(level);
    glutAddMenuEntry("3 LEVELS",3);
    glutAddMenuEntry("4 LEVELS",4);
    glutAddMenuEntry("5 LEVELS",5);
}

there is no problem when the first and second menus are running. but as soon as i add the third menu, i get the error
"Unhandled exception at 0x10031fa6 in openGL2.exe: 0xC0000005: Access violation writing location 0x00000140" in "glut_std.h"
file once defining "glutCreateMenu":
C++
"static int FGAPIENTRY FGUNUSED glutCreateMenu_ATEXIT_HACK(void (* func)(int)) {
  return __glutCreateMenuWithExit(func, exit); }".


how can i fix it? (if i can reduce the code, there is no problem. So i have to give all codes.)
Posted
Updated 28-Dec-14 3:00am
v2
Comments
George Jonsson 28-Dec-14 9:01am    
Have you tried to set a breakpoint inside the method level?
[no name] 28-Dec-14 13:05pm    
Check your line "int sub_menu3 = glutCreateMenu(level);" which even will not compile with the code you posted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900