Board index » cppbuilder » wglCreateContext random access violation

wglCreateContext random access violation

Hi

My program randomly gives access violations when I create a new OpenGl
window (say 25% of the time). The de{*word*81} says the problem is in "hrc =
wglCreateContext(hdc);". The error message is:

Project PHT_View.exe raised exception class C0000005 with message 'access
violation at 0xbff24dd5: read of address 0x81e65000. Process stopped. use
Step or Run to continue.

Any ideas?

Peter

 

Re:wglCreateContext random access violation


I use OpenGL with Borland a lot.  I have never had this problem.  Is your
hdc valid?  How do you obtain it?

Did you disable the floating point error handlers (details can be found on
my OpenGL page).  Although this "fix" seems unrelated, it generally
eliminates "random" crashes in Borland/OpenGL applications.

--
Regards,
Scott
http://members.home.net/scottheiman/

Re:wglCreateContext random access violation


Scott / All

Thanks for the reply

I already had - the basic _control87(MCW_EM, MCW_EM) does not stop all the
problems, I found that _clear87() after each routine makes calls OpenGL is
necessary as well.

My current problem occurs on wglCreateContext and seems to only happen 25%
of the time - and I so far noticed it if the Borland IDE is running (which
is most of the time since I am still building).

void __fastcall TOpenGLView::FormCreate(TObject *Sender)
{
    hdc = GetDC(Handle);
    SetPixelFormatDescriptor();
    hrc = wglCreateContext(hdc);   <<< Dies here
   ...

Quote
}

void __fastcall TOpenGLView::SetPixelFormatDescriptor()
{
    PIXELFORMATDESCRIPTOR pfd = {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
        PFD_TYPE_RGBA,
        24,              // 24-bit colour depth
        0,0,0,0,0,0,
        0,0,
        0,0,0,0,0,
        32,              // 32-bit z-buffer
        0,
        0,
        PFD_MAIN_PLANE,
        0,
        0,0,0
    };
    PixelFormat = ChoosePixelFormat(hdc, &pfd);
    SetPixelFormat(hdc, PixelFormat, &pfd);

Quote
}

I may have made some standard Windows faux-pas.

Any ideas out there?

Best wishes...

Peter

Quote
"Scott Heiman" <who...@nospam.net> wrote in message

news:3bcf6718$1_2@dnews...
Quote
> I use OpenGL with Borland a lot.  I have never had this problem.  Is your
> hdc valid?  How do you obtain it?

> Did you disable the floating point error handlers (details can be found on
> my OpenGL page).  Although this "fix" seems unrelated, it generally
> eliminates "random" crashes in Borland/OpenGL applications.

> --
> Regards,
> Scott
> http://members.home.net/scottheiman/

Re:wglCreateContext random access violation


Quote
Peter Townsley wrote:
> I may have made some standard Windows faux-pas.

Yes, you don't check for errors.

Does any of the calls to GetDC, Choose/SetPixelFormat fail?

HTH
Clemens

Other Threads