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:
parent
49f42e98f4
commit
c09febc4d8
1 changed files with 2 additions and 2 deletions
|
|
@ -11,9 +11,9 @@ void EventsExample::init()
|
||||||
void EventsExample::onEvent(const sp::Event& event)
|
void EventsExample::onEvent(const sp::Event& event)
|
||||||
{
|
{
|
||||||
if (event.type == sp::Event::Key) {
|
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";
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue