From eaa3a999acb28f74952d4a3c328f6f8b555e21d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Mon, 6 Oct 2008 20:52:19 +0000 Subject: [PATCH] Fix the gMainApp race on launch in a cleaner way. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27895 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainApp.cpp | 31 +++++++++++++++++++++---------- src/apps/mediaplayer/MainApp.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/apps/mediaplayer/MainApp.cpp b/src/apps/mediaplayer/MainApp.cpp index 93efbe18d6..a5aef1e7d6 100644 --- a/src/apps/mediaplayer/MainApp.cpp +++ b/src/apps/mediaplayer/MainApp.cpp @@ -51,12 +51,6 @@ MainApp::MainApp() fMediaServerRunning(false), fMediaAddOnServerRunning(false) { - // XXX: HACK HACK HACK - // this works around a locking issue where gMainApp isn't set yet, - // while NewWindow() calls Show() which in the window thread calls - // Controller::PlayerActivated() which calls gMainApp->PlayerCount() - gMainApp = this; - fFirstWindow = NewWindow(); } @@ -79,11 +73,25 @@ MainApp::QuitRequested() BWindow* -MainApp::NewWindow() +MainApp::FirstWindow() { + BAutolock _(this); + if (fFirstWindow) + return fFirstWindow; + return NewWindow(); +} + + +BWindow* +MainApp::NewWindow() +{ + BWindow* win; BAutolock _(this); fPlayerCount++; - return new MainWin(); + win = new MainWin(); + if (!fFirstWindow) + fFirstWindow = win; + return win; } @@ -101,6 +109,9 @@ MainApp::PlayerCount() const void MainApp::ReadyToRun() { + // make sure we have at least one window open + FirstWindow(); + // setup the settings window now, we need to have it fSettingsWindow = new SettingsWindow(BRect(150, 150, 450, 520)); fSettingsWindow->Hide(); @@ -134,7 +145,7 @@ MainApp::RefsReceived(BMessage *msg) entry_ref ref; for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) { BWindow *win; - win = (i == 0 && IsLaunching()) ? fFirstWindow : NewWindow(); + win = NewWindow(); BMessage m(B_REFS_RECEIVED); m.AddRef("refs", &ref); win->PostMessage(&m); @@ -244,7 +255,7 @@ MainApp::MessageReceived(BMessage* message) void MainApp::AboutRequested() { - fFirstWindow->PostMessage(B_ABOUT_REQUESTED); + FirstWindow()->PostMessage(B_ABOUT_REQUESTED); } diff --git a/src/apps/mediaplayer/MainApp.h b/src/apps/mediaplayer/MainApp.h index 47ab59fe4a..5b2142b23a 100644 --- a/src/apps/mediaplayer/MainApp.h +++ b/src/apps/mediaplayer/MainApp.h @@ -39,6 +39,7 @@ public: MainApp(); virtual ~MainApp(); + BWindow* FirstWindow(); BWindow* NewWindow(); int32 PlayerCount() const;