glfw/glfw

Crash on my computer

Lombeelo opened this issue · 2 comments

TLDR: glfw somehow broke on my computer (not anyone other's) and i don't know how to fix it without reinstalling Windows.

As I was developing my application using glfw, it stopped starting with those messages:

GLFW Error 65544: WGL: Failed to make context current
GLFW Error 65543: WGL: A forward compatible OpenGL context requested but WGL_ARB_create_context is unavailable
GLFW Error 65544: WGL: Failed to clear current context

I was using precompiled library packed with ImGui. GLFW crashed in glfwCreateWindow().

So... I checked the source code of GLFW for any hints and got nothing. Then i tried to open The Binding of Isaac: Repentance, wich also uses GLFW, and it silently crashes and leaves a crash dump with analysis result below.
isaacv1.7.9b.J835-20240514-225417-22520-22524.dmp


*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************


KEY_VALUES_STRING: 1

    Key  : AV.Dereference
    Value: NullClassPtr

    Key  : AV.Fault
    Value: Read

    Key  : Analysis.CPU.mSec
    Value: 1250

    Key  : Analysis.DebugAnalysisManager
    Value: Create

    Key  : Analysis.Elapsed.mSec
    Value: 2413

    Key  : Analysis.Init.CPU.mSec
    Value: 1343

    Key  : Analysis.Init.Elapsed.mSec
    Value: 8528

    Key  : Analysis.Memory.CommitPeak.Mb
    Value: 110

    Key  : Timeline.Process.Start.DeltaSec
    Value: 1


FILE_IN_CAB:  isaacv1.7.9b.J835-20240514-225417-22520-22524.dmp

APPLICATION_VERIFIER_FLAGS:  0

CONTEXT:  (.ecxr)
eax=00000000 ebx=000003c0 ecx=00000000 edx=013d07e9 esi=01397a30 edi=00000000
eip=0113195d esp=0039f3d0 ebp=0039f3ec iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00210202
isaac_ng!epoxy_handle_external_wglMakeCurrent+0x55a33d:
0113195d 8b9f18020000    mov     ebx,dword ptr [edi+218h] ds:002b:00000218=????????
Resetting default scope

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 0113195d (isaac_ng!epoxy_handle_external_wglMakeCurrent+0x0055a33d)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000000
   Parameter[1]: 00000218
Attempt to read from address 00000218

PROCESS_NAME:  isaac-ng.exe

READ_ADDRESS:  00000218 

ERROR_CODE: (NTSTATUS) 0xc0000005 -                      0x%p                               0x%p.                      %s.

EXCEPTION_CODE_STR:  c0000005

EXCEPTION_PARAMETER1:  00000000

EXCEPTION_PARAMETER2:  00000218

STACK_TEXT:  
WARNING: Stack unwind information not available. Following frames may be wrong.
0039f3ec 0118fa12     686c6dcf 0082a370 0090ca58 isaac_ng!epoxy_handle_external_wglMakeCurrent+0x55a33d
0039f438 0105bce8     0133710c 005bf000 0105bce8 isaac_ng!epoxy_has_gl_extension+0x26712
0039f8a0 011bb7b6     00000001 0090ca58 0082a370 isaac_ng!epoxy_handle_external_wglMakeCurrent+0x4846c8
0039f8e8 76d3fcc9     005bf000 76d3fcb0 0039f954 isaac_ng!epoxy_has_wgl_extension+0x2b846
0039f8f8 771f7cbe     005bf000 186b0a3f 00000000 kernel32!BaseThreadInitThunk+0x19
0039f954 771f7c8e     ffffffff 77218d5f 00000000 ntdll!__RtlUserThreadStart+0x2f
0039f964 00000000     0142f310 005bf000 00000000 ntdll!_RtlUserThreadStart+0x1b


STACK_COMMAND:  ~0s; .ecxr ; kb

SYMBOL_NAME:  isaac_ng+55a33d

MODULE_NAME: isaac_ng

IMAGE_NAME:  isaac-ng.exe

FAILURE_BUCKET_ID:  NULL_CLASS_PTR_READ_c0000005_isaac-ng.exe!Unknown

OSPLATFORM_TYPE:  x86

OSNAME:  Windows 10

FAILURE_ID_HASH:  {29575a78-112d-c97e-61bc-96392d3ce593}

Followup:     MachineOwner
---------

Minimal reproducible example (my code trimmed):


#define GL_SILENCE_DEPRECATION
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <GLES2/gl2.h>
#endif
#include <GLFW/glfw3.h> // Will drag system OpenGL headers


// Main code
int main(int, char**) 
{
    if (!glfwInit())
        return 1;

    // Decide GL+GLSL versions
#if defined(IMGUI_IMPL_OPENGL_ES2)
    // GL ES 2.0 + GLSL 100
    const char* glsl_version = "#version 100";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
#elif defined(__APPLE__)
    // GL 3.2 + GLSL 150
    const char* glsl_version = "#version 150";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  // 3.2+ only
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);            // Required on Mac
#else
    // GL 3.0 + GLSL 130
    const char* glsl_version = "#version 130";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  // 3.2+ only
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);            // 3.0+ only
#endif

    //glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    // Create window with graphics context
    GLFWwindow* glwindow = glfwCreateWindow(1600, 900, "test", nullptr, nullptr);
    if (glwindow == nullptr)
        return 1;
    return 0;
 }

I checked wglMakeCurrent in Windows, It returns ERROR_INVALID_HANDLE.

Found the culprit! Error happens when i have my second monitor connected :) Fuck you, Microsoft.
Btw when calling GetDC() inside EnumerateWindows() it gets dc for every window on every screen.