Skip to content

Access violation in WglContext destructor when closing the window #3481

Description

@swagween

Prerequisite Checklist

Describe your issue here

When closing an sf::RenderWindow where pollEvents() has been invoked on said window, the existence of any sf::Music instances will cause an access violation crash on window closure.

Your Environment

  • OS / distro / window manager: Windows 11

  • SFML version: 3.0

  • Compiler / toolchain: MVSC

  • Special compiler / CMake flags: NA

  • Build Configuration: ASan / Debug

  • CPU: AMD Ryzen 7 5700X 8-Core

  • GPU: NVIDIA GeForce RTX 3060

Steps to reproduce

  1. Navigate to Settings app in Windows
  2. Go to Bluetooth & devices
  3. Go to Pen & Windows Ink
  4. Enable shell handwriting
  5. Restart your machine if it was not previously enabled
  6. Launch the program and close the window
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>

int main() {
	sf::RenderWindow window{sf::VideoMode({400, 300}), "Crash City", sf::Style::Default, sf::State::Windowed};
	sf::Music music{};
	while (window.isOpen()) {
		while (std::optional const event = window.pollEvent()) {
			if (event->is<sf::Event::Closed>()) { window.close(); }
		}

		window.clear();
		window.display();
	}
	return EXIT_SUCCESS;
}

Expected behavior

Closing the window should not cause an access violation.

Actual behavior

Closing the window causes an access violation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions