Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: ContextWGL crash after updating from 1.5 to 2.0 beta  (Read 12247 times)

0 Members and 1 Guest are viewing this topic.

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
ContextWGL crash after updating from 1.5 to 2.0 beta
« on: December 03, 2009, 07:43:17 pm »
I've tried searching the forums to see if someone else has been having this problem, but I didn't find anything.

My problem is that after updating my game from 1.5 to 2.0 it keeps crashing every time I exit the application. So I put together a minimal app to see if it still happens, and it does. I don't know whether it's an SFML issue, or a driver issue, or me screwing something up. I'm running the latest drivers for my graphics card.

So, the exact problem is that when I exit out of the app, it gives me an unhandled exception, and the issue appears to be on line 91 of ContextWGL.cpp:

Code: [Select]
   if (myContext)
    {
        if (wglGetCurrentContext() == myContext)
---->       wglMakeCurrent(NULL, NULL);
        wglDeleteContext(myContext);
    }


My call stacks looks like this:

    
Code: [Select]
   atioglxx.dll!6903a3ad()
  [Frames below may be incorrect and/or missing, no symbols loaded for atioglxx.dll]
  atioglxx.dll!690925d5()
  opengl32.dll!676e9286()
  opengl32.dll!676e9583()
> sfml-window-d.dll!sf::priv::ContextWGL::~ContextWGL()  Line 91 + 0xc bytes C++
  sfml-window-d.dll!`anonymous namespace'::`dynamic atexit destructor for 'referenceContext''()  + 0x28 bytes C++
  sfml-window-d.dll!_CRT_INIT(void * hDllHandle=0x00100000, unsigned long dwReason=0x00000000, void * lpreserved=0x00000001)  Line 449 C
  sfml-window-d.dll!__DllMainCRTStartup(void * hDllHandle=0x00100000, unsigned long dwReason=0x00000000, void * lpreserved=0x00000001)  Line 560 + 0x11 bytes C
  sfml-window-d.dll!_DllMainCRTStartup(void * hDllHandle=0x00100000, unsigned long dwReason=0x00000000, void * lpreserved=0x00000001)  Line 510 + 0x11 bytes C


And the code for my minimal program looks like this:

Code: [Select]
#include <SFML/Window.hpp>

int main()
{
sf::VideoMode mode;
mode.Width = 1280;
mode.Height = 800;
mode.BitsPerPixel = 32;

sf::Window Screen;
Screen.Create(mode, "oglgame");

return 0;
}


I'm going to feel really stupid if I'm just missing a line or two. :)

Edit: If I run in release instead of debug it instead seems to crash in crtdll.c on line 449:
Code: [Select]
                       /* call the function, which can eventually change __onexitbegin and __onexitend */
                        (*function_to_call)();

         ---->          onexitbegin_new = (_PVFV *)_decode_pointer(__onexitbegin);
                        onexitend_new = (_PVFV *)_decode_pointer(__onexitend);


And the call stack then looks like this:
Code: [Select]
atioglxx.dll!6903a3ad()
  [Frames below may be incorrect and/or missing, no symbols loaded for atioglxx.dll]
  atioglxx.dll!690925d5()
  opengl32.dll!67ed9286()
  opengl32.dll!67ed9583()
  sfml-window.dll!sf::priv::ContextWGL::~ContextWGL()  + 0x24 bytes C++
> sfml-window.dll!_CRT_INIT(void * hDllHandle=0x001c409c, unsigned long dwReason=0x001c4080, void * lpreserved=0x001c4080)  Line 449 C

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #1 on: December 03, 2009, 08:46:18 pm »
It looks like the same bug as in this topic:
http://www.sfml-dev.org/forum/viewtopic.php?t=1824
Laurent Gomila - SFML developer

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #2 on: December 04, 2009, 06:44:30 am »
Ouch, and there's no solution to be found in that topic. :)
Should I post there or here? I guess I'll continue posting here since that person appears to have disappeared. Well, I guess I can tell you what I'm using:

Visual Studio 2008
ATI Radeon 5850, using the latest (9.11) drivers
Windows 7 64-bit

I'm going to see if I can try it out on another computer. I have a feeling this might be an ATI issue.

Edit: I tried it out on another computer running 64-bit Vista, 9.10 drivers and a 3000-series ATI card. Same crash. I'll see if I can bother someone with an nvidia/intel card tomorrow, but it looks like this might be an ati-only issue.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #3 on: December 04, 2009, 07:31:48 am »
Don't bother trying on different computers, I'm sure that it is an ATI-only issue ;)
Laurent Gomila - SFML developer

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #4 on: December 04, 2009, 07:49:19 am »
Yup, I just managed to convince a friend of mine with an Intel card to give it a go. It works just fine. Is there anything else you need from me that might help you track this down?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #5 on: December 04, 2009, 08:08:43 am »
Send me an ATI card :lol:

Ok, more seriously, we can start testing these pieces of code:
Code: [Select]
#include <SFML/Window.hpp>

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "crash!");
    return 0;
}

Code: [Select]
#include <SFML/Window.hpp>

int main()
{
    sf::Context context;
    return 0;
}

Code: [Select]
#include <SFML/Window.hpp>

int main()
{
    return 0;
}

1 and 2 should crash, I'm not sure about the last one.
Laurent Gomila - SFML developer

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #6 on: December 04, 2009, 08:19:29 am »
They all crash, on the same line as my original code, except your last test, which works fine in Release but has the same crash in Debug. :)
If I had a spare ATI card I'd send you it!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #7 on: December 04, 2009, 09:07:50 am »
Great.

Now create an empty project with no link to SFML, and try this code:
Code: [Select]
#include <windows.h>
#include <GL/gl.h>
#include <cassert>

class Context
{
public :

    Context(Context* shared = NULL) :
        myWindow       (NULL),
        myDeviceContext(NULL),
        myContext      (NULL)
    {
        myWindow = CreateWindowA("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, 1, 1, NULL, NULL, GetModuleHandle(NULL), NULL);
        assert(myWindow != NULL);
        ShowWindow(myWindow, SW_HIDE);

        myDeviceContext = GetDC(myWindow);
        assert(myDeviceContext != NULL);

        CreateContext(shared);
        assert(myContext != NULL);

        MakeCurrent();
    }

    ~Context()
    {
        if (wglGetCurrentContext() == myContext)
            wglMakeCurrent(NULL, NULL);
        wglDeleteContext(myContext);

        ReleaseDC(myWindow, myDeviceContext);
        DestroyWindow(myWindow);
    }

private :

    void MakeCurrent()
    {
        if (wglGetCurrentContext() != myContext)
            wglMakeCurrent(myDeviceContext, myContext);
    }

    void CreateContext(Context* shared)
    {
        PIXELFORMATDESCRIPTOR descriptor;
        ZeroMemory(&descriptor, sizeof(descriptor));
        descriptor.nSize        = sizeof(descriptor);
        descriptor.nVersion     = 1;
        descriptor.iLayerType   = PFD_MAIN_PLANE;
        descriptor.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
        descriptor.iPixelType   = PFD_TYPE_RGBA;
        descriptor.cColorBits   = 32;
        descriptor.cDepthBits   = 24;
        descriptor.cStencilBits = 8;
        int format = ChoosePixelFormat(myDeviceContext, &descriptor);
        assert(format != 0);

        PIXELFORMATDESCRIPTOR desc;
        desc.nSize    = sizeof(desc);
        desc.nVersion = 1;
        int ok = SetPixelFormat(myDeviceContext, format, &desc);
        assert(ok != 0);

        myContext = wglCreateContext(myDeviceContext);
        assert(myContext != NULL);

        HGLRC sharedContext = shared ? shared->myContext : NULL;
        if (sharedContext)
        {
            ok = wglShareLists(sharedContext, myContext);
            assert(ok != 0);
        }
    }

    HWND  myWindow;
    HDC   myDeviceContext;
    HGLRC myContext;
};

Context c1;
Context c2(&c1);

int main()
{
    Context c3(&c1);
    return 0;
}
Laurent Gomila - SFML developer

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #8 on: December 04, 2009, 04:54:33 pm »
Sorry about the late reply, I only just got back home.
The code you posted builds and runs without issues both in Debug and Release. Thanks for looking into this. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #9 on: December 04, 2009, 06:39:52 pm »
Arg :(
It is the same code as in SFML, so I expected it to crash as well.

Does your application link to the dynamic version of SFML, or the static one?
Laurent Gomila - SFML developer

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #10 on: December 04, 2009, 07:17:18 pm »
It links dynamically. Should I try linking it statically? I'll just have to figure out how to. :)

Edit: I just tried it with static linking, and it works just fine. No crashing! Even my full game works fine, not just the small tests.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #11 on: December 04, 2009, 10:52:25 pm »
Ok, so that's always the same problem of globals and DLLs mixing badly :)

It won't be easy to solve... but at least there's an easy workaround.

Thanks a lot for your help ;)
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #12 on: December 05, 2009, 12:09:47 am »
I hate dll's :D

Oz1571

  • Newbie
  • *
  • Posts: 28
    • View Profile
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #13 on: December 05, 2009, 12:22:46 am »
You are very welcome! I'd be happy to try it out when/if you think you've found a fix, if I notice you post about it. :) Meanwhile, I'll stick to static dlls. Thanks again.

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
ContextWGL crash after updating from 1.5 to 2.0 beta
« Reply #14 on: February 20, 2010, 03:15:01 am »
Do you happen to be working on a fix Laurent? I figured its been over 2 months so I would ask. I would prefer not to use static for my games and I am having this bug.
Eugene Alfonso
GTP | Twitter