1
0
Fork 0
spectre/examples/events/EventsExample.cpp
Henrik Hautakoski c09febc4d8 examples/events/EventsExample.cpp: store std::string instead of char pointer.
Some compilers (ehm, microsoft) returns a temporary variable for event.key.getKeyName() that is only valid during the statement and not scope.

Fix this by storing std::string instead. So the object's lifetime is the entire if statement.
2020-10-14 13:50:52 +02:00

28 lines
558 B
C++

#include <Spectre/System/MessageHandler.h>
#include <Spectre/System/Log.h>
#include "EventsExample.h"
void EventsExample::init()
{
getMessageHandler()->registerListener(this);
}
void EventsExample::onEvent(const sp::Event& event)
{
if (event.type == sp::Event::Key) {
std::string name = event.key.getKeyName();
const char* pressed = event.key.pressed ? "pressed" : "released";
sp::Log::info("Key: %s %s", name.c_str(), pressed);
}
}
void EventsExample::update(double dt)
{
// Nothing to do
}
void EventsExample::render()
{
// Nothing to do
}