Fix crash on Linux with the new mouse callback introduced in PR #709

The callback is called when the unique_display is null, or display
scale is == 0.
This commit is contained in:
David Capello 2015-07-09 15:08:05 -03:00
parent 56fcf76fc7
commit 3dcffc828d

View File

@ -51,8 +51,25 @@ DlbClk double_click_level;
Event::MouseButton double_click_button = Event::NoneButton;
int double_click_ticks;
inline int display_w() { return (unique_display->width() / unique_display->scale()); }
inline int display_h() { return (unique_display->height() / unique_display->scale()); }
inline int display_w()
{
ASSERT(unique_display);
int scale = unique_display->scale();
ASSERT(scale > 0);
if (scale == 0)
scale = 1;
return (unique_display->width() / scale);
}
inline int display_h()
{
ASSERT(unique_display);
int scale = unique_display->scale();
ASSERT(scale > 0);
if (scale == 0)
scale = 1;
return (unique_display->height() / scale);
}
void update_mouse_position()
{
@ -167,6 +184,10 @@ void osx_mouser_leave_she_callback()
void she_mouse_callback(int flags)
{
// Avoid callbacks when the display is destroyed.
if (!unique_display || unique_display->scale() < 1)
return;
update_mouse_position();
Event ev;
ev.setPosition(gfx::Point(she_mouse_x, she_mouse_y));