Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Error when I close the OpenGL window

  1. #1
    Guest

    Error when I close the OpenGL window

    I use the following code with Borland C++ Builder 6. It works fine and does the following: When I press the button (Button1Click) it creates a separate OpenGL window, with background color blue. Now: When I want to close the window (no matter which) I get the following error : "access violation at 0x40009729: write of address 0x00030c0c. Process stopped" and the Compiler hangs up. Why is this and what`s wrong? When I run the .exe file of this Programm, I do not get a problem, when I quit it.

    *************************************************
    #include <vcl.h>
    #pragma hdrstop
    #include "Basic_U.h"
    #include <GL/glut.h>
    //-----------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //-----------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    {
    }
    //-----------------------------------------------
    void RenderScene(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
    }

    void SetupRC(void)
    {
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    }
    //-----------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutCreateWindow("This is a OpenGL window");
    glutDisplayFunc(RenderScene);
    SetupRC();
    glutMainLoop();
    }
    //-----------------------------------------------

  2. #2
    Junior Member Regular Contributor
    Join Date
    Aug 2004
    Location
    Angers, France
    Posts
    248

    Re: Error when I close the OpenGL window

    Is there any debugger with Borland products ? These typical memory craps aren't a problem for a debugger of a compiler
    The .Product will make you .Believe

  3. #3
    Guest

    Re: Error when I close the OpenGL window

    Yes, I think so. But I have never used it (or another debugger). I am a beginner. What shall I try or do? Now I also have the same problem with the .exe file. Then I get this standard-window you`ll know, where I am asked to send the error message to microsoft.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Aug 2004
    Location
    Angers, France
    Posts
    248

    Re: Error when I close the OpenGL window

    By using the debugger you must run the application in debugging-mode, and just after shutdown program (and not debugging mode) the debugger will ask you if you want to breakpoint the bug that create crap-shutdown, I don't know what's possible to do with your debugger, but generally it show variables where values are strange and breakpoint function where it crack..
    The .Product will make you .Believe

  5. #5
    Guest

    Re: Error when I close the OpenGL window

    Understand. But I think the problem is somwhere else. If you look at the end of my code: You see GlutMainLoop(); This starts OpenGL in a neverending loop. So I guess, this is the problem. But what can I do, the GlutMainLoop() is needed to get OpenGL running? I start GlutMainLoop() with a Button Click from a window. Is this the way one does it?

  6. #6
    Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    368

    Re: Error when I close the OpenGL window

    Since you're creating the OpenGL window at runtime, are you sure you're deleting it? Usually, with glut, one uses exit(0) to exit the program, as glutMainLoop() never returns. I also think that glut redefines this function in glut.h.
    So maybe you can call it on the form's OnClose event or the OnCanClose (or something).

  7. #7
    Guest

    Re: Error when I close the OpenGL window

    ok, I tried exit(0); with another Button-Click. It shuts down the whole Program. What does it realy in the program flow?

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,749

    Re: Error when I close the OpenGL window

    What does your code do ? I can't see what you mean inside it.
    Nevertheless, I'm almost sure you create a first opengl window, then on a click on this window you create another gl window. Isn't it ?

    You encounter context problems doing like that. You might encounter other problems depending on how you wrote your code. Ensure first the good contexts are current when you use one window or another one.

  9. #9
    Guest

    Re: Error when I close the OpenGL window

    Well, indeed I am struggeling with these first steps. I figured out, that I reate new windows, when I put all the functions (glutCreateWindow("foo")....) in my ButtonCall. Then I tried to use one window and update the scenes. Lets say I have one Scene with Points and another one with Linse. I can bring either one in the one window. But I have to change sizes first, bevor the second one is drawn. What do I need to change? I thought glFlush() is all I need to update a scene. This seems to be wrong. Thats my code :

    void Szene(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glPointSize(7.0);
    glBegin(GL_POINTS);
    glColor3f(1.0, 0.0, 0.0);
    glVertex2f(-0.5, -0.5);
    glColor3f(0.0, 1.0, 0.0);
    glVertex2f(-0.5, 0.5);
    glColor3f(0.0, 0.0, 1.0);
    glVertex2f(0.5, 0.5);
    glColor3f(1.0, 1.0, 0.0);
    glVertex2f(0.5, -0.5);
    glEnd();
    glFlush();
    }

    void Scene2(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
    glColor3f(1.0, 0.0, 0.0);
    glVertex2f(-0.4, -0.4);
    glColor3f(0.0, 1.0, 0.0);
    glVertex2f(-0.4, 0.4);
    glColor3f(0.0, 0.0, 1.0);
    glVertex2f(0.4, 0.4);
    glColor3f(1.0, 1.0, 0.0);
    glVertex2f(0.4, -0.4);
    glEnd();
    glFlush();
    }

    void InitOpenGL(void)
    {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //black
    glColor3f(1.0, 1.0, 1.0); //white
    //View : Standard orthogonal / default:
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
    }

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(0,0);
    glutCreateWindow("OpenGL active");
    glutDisplayFunc(Scene);
    InitOpenGL();
    glutMainLoop();
    }
    //-----------------------------------------------

    void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
    {
    exit(0);
    }
    //-----------------------------------------------

    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    glutDisplayFunc(Scene2);
    }
    //-----------------------------------------------

  10. #10
    Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    368

    Re: Error when I close the OpenGL window

    Trivial, my dear Watson, trivial (Holmes grins)
    Put a glutPostRedisplay(); after your glFlush();
    It tells glut that the display has changed and needs to be redrawn.
    Also if you move things around in your scene, you will need double buffers. You only need to change
    glutInit and instead of GLUT_SINGLE aks for GLUT_DOUBLE. Normally you would need to swap buffers by hand, but I'm 99% sure that glutPostRedisplay() is kind enough to provide this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •