Merge pull request #743 from parkerlamb/startup_race

Prevent race condition during emulator startup (issue #702)
This commit is contained in:
Justin Moore 2017-08-03 21:36:22 -05:00 committed by GitHub
commit d081cf5f5c
7 changed files with 48 additions and 1 deletions

View File

@ -266,6 +266,8 @@ bool EmulatorWindow::Initialize() {
window_->Resize(1280, 720); window_->Resize(1280, 720);
window_->DisableMainMenu();
return true; return true;
} }

View File

@ -178,6 +178,9 @@ int xenia_main(const std::vector<std::wstring>& args) {
evt->Set(); evt->Set();
}); });
// Enable the main menu now that the emulator is properly loaded
emulator_window->window()->EnableMainMenu();
// Grab path from the flag or unnamed argument. // Grab path from the flag or unnamed argument.
std::wstring path; std::wstring path;
if (!FLAGS_target.empty() || args.size() >= 2) { if (!FLAGS_target.empty() || args.size() >= 2) {

View File

@ -641,8 +641,8 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
return X_STATUS_UNSUCCESSFUL; return X_STATUS_UNSUCCESSFUL;
} }
on_launch();
main_thread_ = main_xthread->thread(); main_thread_ = main_xthread->thread();
on_launch();
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
} }

View File

@ -19,6 +19,8 @@
namespace xe { namespace xe {
namespace ui { namespace ui {
class Window;
class MenuItem { class MenuItem {
public: public:
typedef std::unique_ptr<MenuItem, void (*)(MenuItem*)> MenuItemPtr; typedef std::unique_ptr<MenuItem, void (*)(MenuItem*)> MenuItemPtr;
@ -51,6 +53,9 @@ class MenuItem {
void RemoveChild(MenuItem* child_item); void RemoveChild(MenuItem* child_item);
MenuItem* child(size_t index); MenuItem* child(size_t index);
virtual void EnableMenuItem(Window& window) = 0;
virtual void DisableMenuItem(Window& window) = 0;
protected: protected:
MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey, MenuItem(Type type, const std::wstring& text, const std::wstring& hotkey,
std::function<void()> callback); std::function<void()> callback);

View File

@ -44,6 +44,9 @@ class Window {
OnMainMenuChange(); OnMainMenuChange();
} }
virtual void EnableMainMenu() = 0;
virtual void DisableMainMenu() = 0;
const std::wstring& title() const { return title_; } const std::wstring& title() const { return title_; }
virtual bool set_title(const std::wstring& title) { virtual bool set_title(const std::wstring& title) {
if (title == title_) { if (title == title_) {

View File

@ -174,6 +174,18 @@ void Win32Window::OnClose() {
super::OnClose(); super::OnClose();
} }
void Win32Window::EnableMainMenu() {
if (main_menu_) {
main_menu_->EnableMenuItem(*this);
}
}
void Win32Window::DisableMainMenu() {
if (main_menu_) {
main_menu_->DisableMenuItem(*this);
}
}
bool Win32Window::set_title(const std::wstring& title) { bool Win32Window::set_title(const std::wstring& title) {
if (!super::set_title(title)) { if (!super::set_title(title)) {
return false; return false;
@ -698,6 +710,22 @@ Win32MenuItem::~Win32MenuItem() {
} }
} }
void Win32MenuItem::EnableMenuItem(Window& window) {
int i = 0;
for (auto iter = children_.begin(); iter != children_.end(); ++iter, i++) {
::EnableMenuItem(handle_, i, MF_BYPOSITION | MF_ENABLED);
}
DrawMenuBar((HWND)window.native_handle());
}
void Win32MenuItem::DisableMenuItem(Window& window) {
int i = 0;
for (auto iter = children_.begin(); iter != children_.end(); ++iter, i++) {
::EnableMenuItem(handle_, i, MF_BYPOSITION | MF_GRAYED);
}
DrawMenuBar((HWND)window.native_handle());
}
void Win32MenuItem::OnChildAdded(MenuItem* generic_child_item) { void Win32MenuItem::OnChildAdded(MenuItem* generic_child_item) {
auto child_item = static_cast<Win32MenuItem*>(generic_child_item); auto child_item = static_cast<Win32MenuItem*>(generic_child_item);

View File

@ -30,6 +30,9 @@ class Win32Window : public Window {
NativeWindowHandle native_handle() const override { return hwnd_; } NativeWindowHandle native_handle() const override { return hwnd_; }
HWND hwnd() const { return hwnd_; } HWND hwnd() const { return hwnd_; }
void EnableMainMenu() override;
void DisableMainMenu() override;
bool set_title(const std::wstring& title) override; bool set_title(const std::wstring& title) override;
bool SetIcon(const void* buffer, size_t size) override; bool SetIcon(const void* buffer, size_t size) override;
@ -92,6 +95,9 @@ class Win32MenuItem : public MenuItem {
HMENU handle() { return handle_; } HMENU handle() { return handle_; }
void EnableMenuItem(Window& window) override;
void DisableMenuItem(Window& window) override;
using MenuItem::OnSelected; using MenuItem::OnSelected;
protected: protected: