From 0b3829810f1df51b106a9cc7cbab70ef9e7af07d Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 11 Dec 2010 14:29:05 +0000 Subject: [PATCH] Don't crash if WindowBuild fails. --- src/Main/CameraGroup.cxx | 17 +++++++++-------- src/Main/WindowBuilder.cxx | 2 ++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Main/CameraGroup.cxx b/src/Main/CameraGroup.cxx index 1c0bb6cca..e80e0c564 100644 --- a/src/Main/CameraGroup.cxx +++ b/src/Main/CameraGroup.cxx @@ -646,15 +646,16 @@ CameraInfo* CameraGroup::buildGUICamera(SGPropertyNode* cameraNode, const SGPropertyNode* windowNode = (cameraNode ? cameraNode->getNode("window") : 0); - if (!window) { - if (windowNode) { - // New style window declaration / definition - window = wBuild->buildWindow(windowNode); - - } else { - return 0; - } + if (!window && windowNode) { + // New style window declaration / definition + window = wBuild->buildWindow(windowNode); } + + if (!window) { // buildWindow can fail + SG_LOG(SG_GENERAL, SG_WARN, "CameraGroup::buildGUICamera: failed to build a window"); + return NULL; + } + Camera* camera = new Camera; camera->setAllowEventFocus(false); camera->setGraphicsContext(window->gc.get()); diff --git a/src/Main/WindowBuilder.cxx b/src/Main/WindowBuilder.cxx index d1c90618f..740671cd5 100644 --- a/src/Main/WindowBuilder.cxx +++ b/src/Main/WindowBuilder.cxx @@ -224,12 +224,14 @@ GraphicsWindow* WindowBuilder::getDefaultWindow() GraphicsContext::Traits* traits = new GraphicsContext::Traits(*defaultTraits); traits->windowName = "FlightGear"; + GraphicsContext* gc = GraphicsContext::createGraphicsContext(traits); if (gc) { defaultWindow = WindowSystemAdapter::getWSA() ->registerWindow(gc, defaultWindowName); return defaultWindow; } else { + SG_LOG(SG_GENERAL, SG_ALERT, "getDefaultWindow: failed to create GraphicsContext"); return 0; } }