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
This commit is contained in:
François Revol
2008-10-06 20:52:19 +00:00
parent d8b7877cf2
commit eaa3a999ac
2 changed files with 22 additions and 10 deletions
+21 -10
View File
@@ -51,12 +51,6 @@ MainApp::MainApp()
fMediaServerRunning(false), fMediaServerRunning(false),
fMediaAddOnServerRunning(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* BWindow*
MainApp::NewWindow() MainApp::FirstWindow()
{ {
BAutolock _(this);
if (fFirstWindow)
return fFirstWindow;
return NewWindow();
}
BWindow*
MainApp::NewWindow()
{
BWindow* win;
BAutolock _(this); BAutolock _(this);
fPlayerCount++; fPlayerCount++;
return new MainWin(); win = new MainWin();
if (!fFirstWindow)
fFirstWindow = win;
return win;
} }
@@ -101,6 +109,9 @@ MainApp::PlayerCount() const
void void
MainApp::ReadyToRun() MainApp::ReadyToRun()
{ {
// make sure we have at least one window open
FirstWindow();
// setup the settings window now, we need to have it // setup the settings window now, we need to have it
fSettingsWindow = new SettingsWindow(BRect(150, 150, 450, 520)); fSettingsWindow = new SettingsWindow(BRect(150, 150, 450, 520));
fSettingsWindow->Hide(); fSettingsWindow->Hide();
@@ -134,7 +145,7 @@ MainApp::RefsReceived(BMessage *msg)
entry_ref ref; entry_ref ref;
for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) { for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) {
BWindow *win; BWindow *win;
win = (i == 0 && IsLaunching()) ? fFirstWindow : NewWindow(); win = NewWindow();
BMessage m(B_REFS_RECEIVED); BMessage m(B_REFS_RECEIVED);
m.AddRef("refs", &ref); m.AddRef("refs", &ref);
win->PostMessage(&m); win->PostMessage(&m);
@@ -244,7 +255,7 @@ MainApp::MessageReceived(BMessage* message)
void void
MainApp::AboutRequested() MainApp::AboutRequested()
{ {
fFirstWindow->PostMessage(B_ABOUT_REQUESTED); FirstWindow()->PostMessage(B_ABOUT_REQUESTED);
} }
+1
View File
@@ -39,6 +39,7 @@ public:
MainApp(); MainApp();
virtual ~MainApp(); virtual ~MainApp();
BWindow* FirstWindow();
BWindow* NewWindow(); BWindow* NewWindow();
int32 PlayerCount() const; int32 PlayerCount() const;