SFML Failed to Create Window’s Context (Single Threaded)

I’m building a game engine, and I made a custom interface to the OS (it’s barebones for now, but I plan to expand it) that I can reimplement for each platform to keep things cross-platform. My current implementation is quick & dirty using SFML middleware to save time during testing (I eventually plan to port to Windows/D3D or GTK/Vulkan). However, I’m getting the error “Failed to Create Window’s Context.” I looked online for people with the same problem, but it almost always arose from multithreading. However, I haven’t done any multithreading optimizations yet, so my code has no threads. I have no usage whatsoever of std::async/std::thread (or equivalents). Instead, I have a basic window class in my header os.hpp, and a simple SFML implementation in os.cpp.

I’m not too familiar with SFML, as it’s been a long time since I’ve used it–so I’ve probably made a rookie mistake. However, I’ve not been able to catch it and I’ve been stuck on this for hours. I just want to get something quick and dirty working so I can actually focus on the meat of the engine.

To make the code more readable and concise, I took the os::Window class and interspersed the header and the implementation (of course, the implementation & the header are seperate, hence the weird design–since SFML & osWindow aren’t available in the header, so that I can change implementation details down the line).

struct Window
{
    Window(Shader const& shader) : shader(shader)
    {
        data = new osWindow;
        osWindow* ptr = (osWindow*)data;

        // Shader just stores file paths for the vertex/pixel shader
        ptr->shader.loadFromFile(shader.vertex, shader.pixel);
        ptr->window.create(sf::WindowHandle("Osmium"));
    }

    // Hide the Window
    void hide(void) { ((osWindow*)data)->window.close(); }

    void os::Window::show(void)
    {
        delete data;

        data = new osWindow;
        osWindow* ptr = (osWindow*)data;

        ptr->shader.loadFromFile(shader.vertex, shader.pixel);
        ptr->window.create(sf::WindowHandle("Osmium"));
    }

    void loop(std::function<void(Window&)> proc)
    {
        bool running = true;

        while (running)
        {
            sf::RenderWindow& window = ((osWindow*)data)->window;

            sf::Event event;
            while (ptr->window.pollEvent(event))
                if (event.type == sf::Event::Closed)
                    running = false;

            proc(*this);

            // Logic to draw the entire window with the shader -- Will be expanded later
        }
    }

    template<class T>
    void setUniform(std::string const& uniform, T const& value) { ((osWindow*)data)->shader.setUniform(uniform, value); }

    ~Window() { delete data; }
private:
    Shader const& shader;
    bool displayed = false;
    void* data = nullptr;
};

I’ve tried a lot of stuff. I thought at first that it was the shaders, but after looking at SFML/Window.cpp, I found that the error is printed when the setActive function fails, so it was before the shaders were being used. Additionally, when testing by printing out the frame number to stdout every frame in proc, I found that the error was being printed multiple times a frame. I can’t tell where in the window class the error is, though, and printing at various points has raised more questions that it’s answered.

At this point, I’m very sure it is not proc, vertex.glsl (my vertex shader), pixel.glsl (the corresponding pixel shader), or the Shader struct (which is very simple). I’m 90% sure it’s somewhere in this Window struct.

New contributor

Spencer Rosas-Gunn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật