From 35d9107d8147efcea441fbac3f3a24da1e161c45 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 4 Jan 2008 13:57:36 +0000 Subject: [PATCH] Added catch for handling cases where undefined settings for dislayNum and screenNum are used --- include/osg/GraphicsContext | 17 +++++++++++++++-- src/osg/GraphicsContext.cpp | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index 483ab89d9..5b0aaa751 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -38,12 +38,25 @@ class OSG_EXPORT GraphicsContext : public Object /** Return the display name in the form hostName::displayNum:screenNum. */ std::string displayName() const; - /** Read the DISPLAY environmental variable, and set the ScreenIdentifier accordingly.*/ + /** Read the DISPLAY environmental variable, and set the ScreenIdentifier accordingly. + * Note, if either of displayNum or screenNum are not defined then -1 is set respectively to + * signify the this parameter has not been set. When parameters are undefined one can call + * call setUndefinedScreenDetalstoDefaultScreen() method after readDISPLAY() to ensure valid values. */ void readDISPLAY(); - /** Set the screenIndentifier from the displayName string.*/ + /** Set the screenIndentifier from the displayName string. + * Note, if either of displayNum or screenNum are not defined then -1 is set respectively to + * signify the this parameter has not been set. When parameters are undefined one can call + * call setUndefinedScreenDetalstoDefaultScreen() method after readDISPLAY() to ensure valid values. */ void setScreenIdentifier(const std::string& displayName); + /** Set any undefined displayNum or screenNum values (i.e. -1) to the default display & screen of 0 respectively.*/ + void setUndefinedScreenDetailsToDefaultScreen() + { + if (displayNum<0) displayNum = 0; + if (screenNum<0) screenNum = 0; + } + std::string hostName; int displayNum; int screenNum; diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index 7a4ed8434..ea34985eb 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -55,7 +55,12 @@ GraphicsContext::WindowingSystemInterface* GraphicsContext::getWindowingSystemIn GraphicsContext* GraphicsContext::createGraphicsContext(Traits* traits) { if (s_WindowingSystemInterface.valid()) + { + // catch any undefined values. + if (traits) traits->setUndefinedScreenDetailsToDefaultScreen(); + return s_WindowingSystemInterface->createGraphicsContext(traits); + } else return 0; }