mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-30 23:12:36 +00:00
attempt to fix crash when wml erros message showed during the loadingscreen.
This commit is contained in:
parent
6977908b69
commit
fb2e87b36b
@ -39,6 +39,17 @@
|
||||
|
||||
#define ERR_GEN LOG_STREAM(err, lg::general)
|
||||
|
||||
namespace
|
||||
{
|
||||
struct invoked_function_data
|
||||
{
|
||||
bool finished;
|
||||
const std::function<void(void)>& f;
|
||||
|
||||
void call() { f(); finished = true; }
|
||||
};
|
||||
}
|
||||
|
||||
namespace events
|
||||
{
|
||||
|
||||
@ -413,6 +424,12 @@ void pump()
|
||||
int begin_ignoring = 0;
|
||||
std::vector< SDL_Event > events;
|
||||
while(SDL_PollEvent(&temp_event)) {
|
||||
|
||||
if (temp_event.type == INVOKE_FUNCTION_EVENT) {
|
||||
static_cast<invoked_function_data*>(temp_event.user.data1)->call();
|
||||
continue;
|
||||
}
|
||||
|
||||
++poll_count;
|
||||
peek_for_resize();
|
||||
|
||||
@ -736,6 +753,35 @@ void peek_for_resize()
|
||||
}
|
||||
}
|
||||
|
||||
void call_in_main_thread(const std::function<void(void)>& f)
|
||||
{
|
||||
if (boost::this_thread::get_id() == main_thread) {
|
||||
// nothing special to do if called from the main thread.
|
||||
f();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
invoked_function_data fdata = { false, f };
|
||||
|
||||
SDL_Event sdl_event;
|
||||
SDL_UserEvent sdl_userevent;
|
||||
|
||||
sdl_userevent.type = INVOKE_FUNCTION_EVENT;
|
||||
sdl_userevent.code = 0;
|
||||
sdl_userevent.data1 = &fdata;
|
||||
sdl_userevent.data2 = nullptr;
|
||||
|
||||
sdl_event.type = INVOKE_FUNCTION_EVENT;
|
||||
sdl_event.user = sdl_userevent;
|
||||
|
||||
SDL_PushEvent(&sdl_event);
|
||||
|
||||
while (!fdata.finished) {
|
||||
SDL_Delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //end events namespace
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <SDL_events.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <functional>
|
||||
|
||||
//our user-defined double-click event type
|
||||
#define DOUBLE_CLICK_EVENT SDL_USEREVENT
|
||||
@ -27,6 +28,7 @@
|
||||
#define CLOSE_WINDOW_EVENT (SDL_USEREVENT + 4)
|
||||
#define SHOW_HELPTIP_EVENT (SDL_USEREVENT + 5)
|
||||
#define DRAW_ALL_EVENT (SDL_USEREVENT + 6)
|
||||
#define INVOKE_FUNCTION_EVENT (SDL_USEREVENT + 7)
|
||||
|
||||
namespace events
|
||||
{
|
||||
@ -111,6 +113,8 @@ void focus_handler(const sdl_handler* ptr);
|
||||
|
||||
bool has_focus(const sdl_handler* ptr, const SDL_Event* event);
|
||||
|
||||
void call_in_main_thread(const std::function<void (void)>& f);
|
||||
|
||||
//event_context objects control the handler objects that SDL events are sent
|
||||
//to. When an event_context is created, it will become the current event context.
|
||||
//event_context objects MUST be created in LIFO ordering in relation to each other,
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "addon/manager_old.hpp"
|
||||
#include "ai/configuration.hpp"
|
||||
#include "cursor.hpp"
|
||||
#include "events.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "game_classification.hpp"
|
||||
@ -451,9 +452,9 @@ void game_config_manager::load_addons_cfg()
|
||||
n);
|
||||
|
||||
const std::string& report = utils::join(error_log, "\n\n");
|
||||
|
||||
gui2::dialogs::wml_error::display(msg1, msg2, error_addons, report,
|
||||
video_);
|
||||
events::call_in_main_thread([&]() {
|
||||
gui2::dialogs::wml_error::display(msg1, msg2, error_addons, report, video_);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user