Hi everyone,
This is my first project using C++ and SFML 3.0!
I followed the getting started guide to create a new project in Visual Studio, and I successfully opened a window and drew a shape without any issues.
However, when I tried to use the handleEvents method for handling events instead of polling for them, I encountered an error message. Here’s what I’ve done so far:
#include <SFML/Graphics.hpp>
#include <SFML/Graphics.hpp>
class EventHandler
{
public:
std::optional<std::string> operator()(const sf::Event::Closed& event) {
return "Closed\r\n";
}
std::optional<std::string> operator()(const sf::Event::KeyPressed& event) {
return "Key pressed\r\n";
}
std::optional<std::string> operator()(const sf::Event::MouseButtonPressed& event) {
return "Mouse pressed\r\n";
}
template <typename T>
std::optional<std::string> operator()(const T&) {
return "Unhandled event\r\n";
}
};
int main()
{
sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "My window");
EventHandler eventHandler;
while (window.isOpen())
{
window.handleEvents(
[&](const sf::Event::Closed& event) { eventHandler(event); },
[&](const sf::Event::KeyPressed& event) { eventHandler(event); }
);
window.display();
}
}
The compiler shows the following error message:
in function 'void __thiscall sf::WindowBase::handleEvents<class `int __cdecl main(void)'::`4'::<lambda_1>,class `int __cdecl main(void)'::`4'::<lambda_2> >(class `int __cdecl main(void)'::`4'::<lambda_1> &&,class `int __cdecl main(void)'::`4'::<lambda_2> &&)' buffer 'overloadSet' of size 12 bytes will be overrun; 4 bytes will be written starting at offset 9
I'm not sure what I'm doing wrong. Any help or guidance would be greatly appreciated!