1
0
Fork 0

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.
This commit is contained in:
Henrik Hautakoski 2020-10-14 13:50:52 +02:00
parent 49f42e98f4
commit c09febc4d8

View file

@ -11,9 +11,9 @@ void EventsExample::init()
void EventsExample::onEvent(const sp::Event& event)
{
if (event.type == sp::Event::Key) {
const char* name = event.key.getKeyName().c_str();
std::string name = event.key.getKeyName();
const char* pressed = event.key.pressed ? "pressed" : "released";
sp::Log::info("Key: %s %s", name, pressed);
sp::Log::info("Key: %s %s", name.c_str(), pressed);
}
}