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

Author Topic: Native Windows  (Read 315 times)

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 3402
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Native Windows
« on: February 19, 2025, 10:14:35 pm »
Is there an example of successfully integrating SFML within a native window in Windows that does not fire off OpenGL warnings?

What I'm talking about here is not a complicated request: just a single native window from which SFML can create a render window.

Since the upgrade from SFML 2 to SFML 3, I've found this to be impossible.

For example, this code:
#include <SFML/Graphics.hpp>
#include <Windows.h>

#include <iostream>

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

int main()
{
        HINSTANCE hInstance{ GetModuleHandle(NULL) };



        // main window
        const wchar_t mainClassName[] = L"Main Window Class";
        WNDCLASS wc = { };
        wc.lpfnWndProc = WindowProcedure;
        wc.hInstance = hInstance;
        wc.lpszClassName = mainClassName;
        RegisterClass(&wc);

        HWND hWnd = CreateWindowEx(
                0, mainClassName, L"SFML in native window test", WS_OVERLAPPEDWINDOW,
                CW_USEDEFAULT, CW_USEDEFAULT, // position
                1000, 1000, // size
                NULL, NULL, hInstance, NULL
        );
        if (!hWnd)
                return EXIT_FAILURE;

        ShowWindow(hWnd, SW_SHOWNORMAL);



        sf::RenderWindow sfmlWindow(hWnd);



        sfmlWindow.clear(sf::Color(255u, 160u, 64u)); // fill the SFML window with a solid colour
        sfmlWindow.display();



        MSG msg{};
        while (GetMessage(&msg, NULL, 0, 0) > 0)
        {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
        }
}

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
        switch (msg)
        {
        case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
        default:
                return DefWindowProc(hWnd, msg, wParam, lParam);
        }
}

as well as this official example:
https://github.com/SFML/SFML/blob/master/examples/win32/Win32.cpp

cause this error since SFML 3:

(that failed call is from here: https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/RenderWindow.cpp#L113)

The error is always thrown on window.create() and is thrown repeatedly and locks the progress of the program. Only in debug mode, however. In release mode, it's fine and the graphics module works as expected.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11145
    • View Profile
    • development blog
    • Email
Re: Native Windows
« Reply #1 on: February 19, 2025, 10:30:07 pm »
I think someone else reported this already, but it totally slipped my mind and I don't think it has been fixed so far.

Edit: Just remembered/found the related issue: https://github.com/SFML/SFML/issues/3369

The issue for the locking up is related to the changed we've done to glCheck that loops over the errors and drains it, which in this case causes more errors, sooo infinite loop.

Not sure if the original RenderWindow error that sets off the loop needs to be looked at as well.
I'll ping some people ;D
« Last Edit: February 19, 2025, 10:33:43 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3402
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Native Windows
« Reply #2 on: February 19, 2025, 10:53:40 pm »
Ah, so it's an error? Okay. I did look to see if I could see anything but didn't see that report.

I'm only just getting around to updating my native stuff to test it with SFML 3 so at least it still works (skips the error) in release mode.

Indeed the looping/locking is obviously the issue here; maybe consider a maximum loop-through counter when attempting to drain? or maybe just check to see if its the same error as the previous one and, if so, stop draining.

Obviously the initial cause of the issue should also be investigated too. The last time I saw this issue was when discussing DPI aware windows(https://en.sfml-dev.org/forums/index.php?topic=29282) although this occurs regardless of DPI awareness.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*