mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 14:38:30 -04:00
AP_OSD: add mutex against maniplating sf windows from different threads
This commit is contained in:
parent
02e34c95c9
commit
32a6f0026a
@ -34,6 +34,8 @@
|
||||
#include <unistd.h>
|
||||
#include "pthread.h"
|
||||
|
||||
#include <AP_Notify/AP_Notify.h>
|
||||
|
||||
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; y<video_lines; y++) {
|
||||
for (uint8_t x=0; x<video_cols; x++) {
|
||||
uint16_t px = x * (char_width+char_spacing) * char_scale;
|
||||
uint16_t py = y * (char_height+char_spacing) * char_scale;
|
||||
sf::Sprite s;
|
||||
uint8_t c = buffer2[y][x];
|
||||
s.setTexture(font[c]);
|
||||
s.setPosition(sf::Vector2f(px, py));
|
||||
s.scale(sf::Vector2f(char_scale,char_scale));
|
||||
w->draw(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; y<video_lines; y++) {
|
||||
for (uint8_t x=0; x<video_cols; x++) {
|
||||
uint16_t px = x * (char_width+char_spacing) * char_scale;
|
||||
uint16_t py = y * (char_height+char_spacing) * char_scale;
|
||||
sf::Sprite s;
|
||||
uint8_t c = buffer2[y][x];
|
||||
s.setTexture(font[c]);
|
||||
s.setPosition(sf::Vector2f(px, py));
|
||||
s.scale(sf::Vector2f(char_scale,char_scale));
|
||||
w->draw(s);
|
||||
}
|
||||
}
|
||||
|
||||
w->display();
|
||||
if (last_font != get_font_num()) {
|
||||
load_font();
|
||||
}
|
||||
}
|
||||
}
|
||||
usleep(10000);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user