Content-Length: 360397 | pFad | http://github.com/dotnet/Silk.NET/issues/2436

4D Error creating multiple windows in .NET 8 · Issue #2436 · dotnet/Silk.NET · GitHub
Skip to content

Error creating multiple windows in .NET 8 #2436

Open
@Av3boy

Description

@Av3boy

Summary

I wanted to build a docking system using ImGui where, when the imgui window is undocked another silk.net window is created to host that tabs content. Just running the window was not possible in the same thread since the Run method would block the "main" window from running. After that I tried to move the new window into it's own thread and I noticed that something wasn't working since I was getting the following error:

Silk.NET.GLFW.GlfwException: 'PlatformError: Win32: Failed to register window class: Class already exists. '

I tried to reproduce the problem in a test project and using .NET 6 this works just fine. However using .NET 8 like the rest of the project, I got the same error using this code (NOTE: The 'usafe' block is just for debugging purposes, doesn't affect the problem itself):

    static void Main()
    {
       // Changing the WindowClass did not work.
        var options1 = WindowOptions.Default with { Title = "Window 1", WindowClass = "MyWindowClass1" };
        var options2 = WindowOptions.Default with { Title = "Window 2", WindowClass = "MyWindowClass2" };

        var window1 = Window.Create(options1);
        var window2 = Window.Create(options2);

        StartWindow(window1);
        StartWindow(window2); // You can uncomment this to see the program working with just one window.
    }

    static void StartWindow(IWindow window)
    {
        var thread = new Thread(() =>
        {
            window.Load += () =>
            {
                var gl = GL.GetApi(window);

                unsafe
                {
                    var versionPtr = gl.GetString(StringName.Version);
                    string? version = SilkMarshal.PtrToString((nint)versionPtr);
                    Console.WriteLine($"OpenGL version: {version}");
                }

            };

            window.Run(); // The GlfwException is thrown here
        });

        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
    }

System info:

  • Platform: Desktop, Windows 11, Insider Preview 10.0.26120.1930
  • Framework Version: .NET 8
  • IDE: Visual Studio Community 2022 Preview, 17.14.0 Preview 2.0
  • API: OpenGL
  • API Version: OpenGL version: 3.3.0 NVIDIA 572.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: http://github.com/dotnet/Silk.NET/issues/2436

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy