diff --git a/libraries/AP_OSD/AP_OSD_SITL.cpp b/libraries/AP_OSD/AP_OSD_SITL.cpp index fd03fe754c..c22097776b 100644 --- a/libraries/AP_OSD/AP_OSD_SITL.cpp +++ b/libraries/AP_OSD/AP_OSD_SITL.cpp @@ -34,6 +34,8 @@ #include #include "pthread.h" +#include + extern const AP_HAL::HAL &hal; /* @@ -128,49 +130,56 @@ void AP_OSD_SITL::flush(void) void AP_OSD_SITL::update_thread(void) { load_font(); - w = new sf::RenderWindow(sf::VideoMode(video_cols*(char_width+char_spacing)*char_scale, - video_lines*(char_height+char_spacing)*char_scale), - "OSD"); + { + WITH_SEMAPHORE(AP::notify().sf_window_mutex); + w = new sf::RenderWindow(sf::VideoMode(video_cols*(char_width+char_spacing)*char_scale, + video_lines*(char_height+char_spacing)*char_scale), + "OSD"); + } if (!w) { AP_HAL::panic("Unable to create OSD window"); } - while (w->isOpen()) { - sf::Event event; - while (w->pollEvent(event)) { - if (event.type == sf::Event::Closed) { - w->close(); - } - } - if (counter == last_counter) { - usleep(10000); - continue; - } - last_counter = counter; - - uint8_t buffer2[video_lines][video_cols]; + while (true) { { - WITH_SEMAPHORE(mutex); - memcpy(buffer2, buffer, sizeof(buffer2)); - } - w->clear(); - - for (uint8_t y=0; ydraw(s); + WITH_SEMAPHORE(AP::notify().sf_window_mutex); + sf::Event event; + while (w->pollEvent(event)) { + if (event.type == sf::Event::Closed) { + w->close(); + } } - } + if (!w->isOpen()) { + break; + } + if (counter != last_counter) { + last_counter = counter; - w->display(); - if (last_font != get_font_num()) { - load_font(); + uint8_t buffer2[video_lines][video_cols]; + { + WITH_SEMAPHORE(mutex); + memcpy(buffer2, buffer, sizeof(buffer2)); + } + w->clear(); + + for (uint8_t y=0; ydraw(s); + } + } + + w->display(); + if (last_font != get_font_num()) { + load_font(); + } + } } usleep(10000); }