Skip to content
Snippets Groups Projects
Commit d3e6e406 authored by Oliver Bock's avatar Oliver Bock
Browse files

Fixed weird "HUD killing bug" (see 29943e253fccba88122977deb1c233ffa2e8dcfe)

* For some reason main() must be structured as it is now
* Moving toggleFullscreen() or setWindowCaption() into initialize() causes the bug to reappear
* I don't yet understand the problem, let's hope that's not some strange race condition
parent 239e56c4
No related branches found
No related tags found
No related merge requests found
...@@ -8,11 +8,8 @@ WindowManager::~WindowManager() ...@@ -8,11 +8,8 @@ WindowManager::~WindowManager()
{ {
} }
bool WindowManager::initialize(const bool fullscreen, const int width, const int height) bool WindowManager::initialize(const int width, const int height)
{ {
// be sure there's at least one observer!
assert(eventObservers.size() > 0);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
cerr << "Window system could not be initalized: " << SDL_GetError() << endl; cerr << "Window system could not be initalized: " << SDL_GetError() << endl;
return false; return false;
...@@ -117,11 +114,6 @@ bool WindowManager::initialize(const bool fullscreen, const int width, const int ...@@ -117,11 +114,6 @@ bool WindowManager::initialize(const bool fullscreen, const int width, const int
m_DesktopBitsPerPixel, m_DesktopBitsPerPixel,
m_VideoModeFlags); m_VideoModeFlags);
// switch to fullscreen if requested
if(fullscreen && m_FullscreenModeAvailable) {
toggleFullscreen();
}
if (m_DisplaySurface == NULL) { if (m_DisplaySurface == NULL) {
cerr << "Could not acquire rendering surface: " << SDL_GetError() << endl; cerr << "Could not acquire rendering surface: " << SDL_GetError() << endl;
return false; return false;
...@@ -323,12 +315,12 @@ int WindowManager::windowHeight() const ...@@ -323,12 +315,12 @@ int WindowManager::windowHeight() const
return m_CurrentHeight; return m_CurrentHeight;
} }
void WindowManager::setWindowCaption(const string caption) void WindowManager::setWindowCaption(const string caption) const
{ {
SDL_WM_SetCaption(caption.c_str(), NULL); SDL_WM_SetCaption(caption.c_str(), NULL);
} }
void WindowManager::setWindowIcon(const string filename) void WindowManager::setWindowIcon(const string filename) const
{ {
if (filename.length() > 0) { if (filename.length() > 0) {
SDL_WM_SetIcon(SDL_LoadBMP(filename.c_str()), NULL); SDL_WM_SetIcon(SDL_LoadBMP(filename.c_str()), NULL);
......
...@@ -18,7 +18,7 @@ public: ...@@ -18,7 +18,7 @@ public:
WindowManager(); WindowManager();
virtual ~WindowManager(); virtual ~WindowManager();
bool initialize(const bool fullscreen, const int width = 1024, const int height = 768); bool initialize(const int width = 1024, const int height = 768);
void registerEventObserver(AbstractGraphicsEngine *engine); void registerEventObserver(AbstractGraphicsEngine *engine);
void unregisterEventObserver(AbstractGraphicsEngine *engine); void unregisterEventObserver(AbstractGraphicsEngine *engine);
void eventLoop(); void eventLoop();
...@@ -26,8 +26,8 @@ public: ...@@ -26,8 +26,8 @@ public:
int windowWidth() const; int windowWidth() const;
int windowHeight() const; int windowHeight() const;
void setWindowCaption(const string caption); void setWindowCaption(const string caption) const;
void setWindowIcon(const string filename); void setWindowIcon(const string filename) const;
void toggleFullscreen(); void toggleFullscreen();
private: private:
......
...@@ -38,44 +38,40 @@ using namespace std; ...@@ -38,44 +38,40 @@ using namespace std;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Starsphere graphics; // prepare main objects
WindowManager window; WindowManager window;
ResourceFactory factory;
// register starsphere as event observer Starsphere graphics;
window.registerEventObserver(&graphics);
#ifdef NDEBUG
const bool fullscreen = true;
#else
const bool fullscreen = false;
#endif
// initialize window manager // initialize window manager
if(!window.initialize(fullscreen)) { if(!window.initialize()) {
window.unregisterEventObserver(&graphics);
exit(1); exit(1);
} }
window.setWindowCaption("Einstein@Home");
// prepare resource factory
ResourceFactory factory;
// create font resource instance // create font resource instance
const Resource *fontResource = factory.createInstance("FontSansSerif"); const Resource *fontResource = factory.createInstance("FontSansSerif");
if(fontResource == NULL) { if(fontResource == NULL) {
cerr << "Font resource could not be loaded!" << endl; cerr << "Font resource could not be loaded!" << endl;
window.unregisterEventObserver(&graphics);
exit(1); exit(1);
} }
if(fontResource->data()->size() == 0) { if(fontResource->data()->size() == 0) {
cerr << "Font resource could not be loaded!" << endl; cerr << "Font resource could not be loaded!" << endl;
window.unregisterEventObserver(&graphics); delete fontResource;
exit(1); exit(1);
} }
window.setWindowCaption("Einstein@Home");
// register starsphere as event observer
window.registerEventObserver(&graphics);
#ifdef NDEBUG
// switch to fullscreen when in release mode
window.toggleFullscreen();
#endif
// pepare rendering // pepare rendering
graphics.initialize(window.windowWidth(), window.windowHeight(), fontResource); graphics.initialize(window.windowWidth(), window.windowHeight(), fontResource);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment