Discussion:
[osg-users] getWindowingSystemInterface() fails on Ubuntu 18.04
Omar Álvarez
2018-09-05 10:41:26 UTC
Permalink
osg::GraphicsContext::WindowingSystemInterface* wsi =
osg::GraphicsContext::getWindowingSystemInterface();
if ( !wsi ) {
std::cout << "ERROR. Could not access the Windowing System
Interface" << std::endl;
throw -1;
}

std::cout << wsi->getNumScreens() << " screen(s) detected" << std::endl;
for ( unsigned int screen=0 ; screen < wsi->getNumScreens(); screen++ )
{
osg::GraphicsContext::ScreenIdentifier screen_id(screen);
osg::GraphicsContext::ScreenSettings screen_settings;
wsi->getScreenSettings( screen_id, screen_settings );
std::cout << " Screen #" << screen << " : "
<< screen_settings.width << "x" << screen_settings.height
<< " "
<< screen_settings.refreshRate << "Hz "
<< screen_settings.colorDepth << " bit" << std::endl;
}

This simple code snippet fails for me on Ubuntu 18.04 (OSG 3.6.2 and 3.4.0)
with:

Invalid MIT-MAGIC-COOKIE-1 keyA Unable to open display ":0.0"
Invalid MIT-MAGIC-COOKIE-1 keyA Unable to open display ":0.0"
0 screen(s) detected
Invalid MIT-MAGIC-COOKIE-1 keyA Unable to open display ":0.0"

I have a dedicated NVIDIA GPU with latest drivers (396), running osgviewer
works properly. I also checked that getWindowingSystemInterface is being
called at the correct time. I have tested this after creating a viewer and
it also fails.

RegisterWindowingSystemInterfaceProxy()
X11WindowingSystemInterface()
GraphicsContext::setWindowingSystemInterface() 0x55aada1ee9d0
0x7f69e2fc9978
GraphicsContext::getWindowingSystemInterface() 0x55aada1ee9d0
0x7f69e2fc9978

Another thing that makes no sense is that my X session is not :0.0 but
:1.*, but no matter what $DISPLAY environment variable has, it is ignored,
it is looking for screens in the wrong X session. At this point I don't
know what else to try. Am I doing something wrong? Any ideas?
Robert Osfield
2018-09-05 11:19:27 UTC
Permalink
Hi Omar,

What happens when you run osgviewer? Do you get errors output to the console?

Do any of the OSG examples fail?

If we can't see the error in standard OSG examples then it may be
worth creating a small test program so that others can run it on their
own systems to see if we can establish a pattern and get to the bottom
of the issue.

Robert.
Omar Álvarez
2018-09-05 11:56:43 UTC
Permalink
Hi Robert,

Thanks for the quick response.

I have created an example:

https://github.com/omaralvarez/osgtest

osgviewer runs fine, no errors in console. But if I use INFO, I can see:

Viewer::realize() - No valid contexts found, setting up view across all
screens.

It may be related, but I'm not sure.

None of the examples I've tried have failed.

Cheers,

Omar.
Post by Robert Osfield
Hi Omar,
What happens when you run osgviewer? Do you get errors output to the console?
Do any of the OSG examples fail?
If we can't see the error in standard OSG examples then it may be
worth creating a small test program so that others can run it on their
own systems to see if we can establish a pattern and get to the bottom
of the issue.
Robert.
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Julien Valentin
2018-09-05 14:03:16 UTC
Permalink
WindowingSystemInterface is an interface implemented in system dependant osgViewer::XXXWindowingSystemInterface
What may be done is to add a system agnotistic windowInterface in osgviewer

#ifdef SYS
typedef osgViewer::SYSWindowingSystemInterface osgViewer::WindowingInterface
#else if SYS2
typedef osgViewer::SYS2WindowingSystemInterface osgViewer::WindowingInterface

In your case try to use osgUtil::X11WindowingSystemInterface

------------------------
Twirling twirling twirling toward freedom

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74653#74653
Robert Osfield
2018-09-05 14:14:10 UTC
Permalink
HI Julian,
Post by Julien Valentin
WindowingSystemInterface is an interface implemented in system dependant osgViewer::XXXWindowingSystemInterface
What may be done is to add a system agnotistic windowInterface in osgviewer
#ifdef SYS
typedef osgViewer::SYSWindowingSystemInterface osgViewer::WindowingInterface
#else if SYS2
typedef osgViewer::SYS2WindowingSystemInterface osgViewer::WindowingInterface
In your case try to use osgUtil::X11WindowingSystemInterface
The WindowingSystemInterface is meant to be accessed in a windowing
agnostic way, end user application shouldn't need to access the
windowing specific version. Omar's code look normal in this respect.

Robert.
Julien Valentin
2018-09-05 14:18:00 UTC
Permalink
Sorry I misinterpreted the code and said bullshit
there's really bug in X11WindowingSystemInterface reporting 0 screens
Post by Julien Valentin
WindowingSystemInterface is an interface implemented in system dependant osgViewer::XXXWindowingSystemInterface
What may be done is to add a system agnotistic windowInterface in osgviewer
#ifdef SYS
typedef osgViewer::SYSWindowingSystemInterface osgViewer::WindowingInterface
#else if SYS2
typedef osgViewer::SYS2WindowingSystemInterface osgViewer::WindowingInterface
In your case try to use osgUtil::X11WindowingSystemInterface
------------------------
Twirling twirling twirling toward freedom

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74654#74654
Julien Valentin
2018-09-05 14:23:58 UTC
Permalink
Sorry again
After a lot of bullshit here's a correct answer
for your code you should replace
wsi->getNumScreens()
with
wsi->getNumScreens(osg::GraphicsContext::ScreenIdentifier(1))
to work on DISPLAY=:1.0
Post by Julien Valentin
Sorry I misinterpreted the code and said bullshit
there's really bug in X11WindowingSystemInterface reporting 0 screens
Post by Julien Valentin
WindowingSystemInterface is an interface implemented in system dependant osgViewer::XXXWindowingSystemInterface
What may be done is to add a system agnotistic windowInterface in osgviewer
#ifdef SYS
typedef osgViewer::SYSWindowingSystemInterface osgViewer::WindowingInterface
#else if SYS2
typedef osgViewer::SYS2WindowingSystemInterface osgViewer::WindowingInterface
In your case try to use osgUtil::X11WindowingSystemInterface
------------------------
Twirling twirling twirling toward freedom

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74656#74656
Robert Osfield
2018-09-05 14:50:42 UTC
Permalink
Post by Julien Valentin
for your code you should replace
wsi->getNumScreens()
with
wsi->getNumScreens(osg::GraphicsContext::ScreenIdentifier(1))
to work on DISPLAY=:1.0
Sounds like we are getting to the bottom of things now :-)

FYI, WindowingSystemInterface::getNumScreens() is implemented in
include/osg/GraphicsContext as:

virtual unsigned int getNumScreens(const ScreenIdentifier&
screenIdentifier = ScreenIdentifier()) = 0;

The default constructed ScreenIdentifier is:

GraphicsContext::ScreenIdentifier::ScreenIdentifier():
displayNum(0),
screenNum(0) {}

Which is fine if the system doesn't change the default DISPLAY from 0.0.

Support for DISPLAY is actually built into ScreenIdentifier via the
readDISPLAY() method:

/** 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 that this parameter has not been set. When
parameters are undefined one can call
* call setUndefinedScreenDetailsToDefaultScreen() after
readDISPLAY() to ensure valid values. */
void readDISPLAY();

To is not called by the constructor though, so you need to call it
explicitly. The various Viewer config implementations do actually
call readDISPLAY:

~/OpenSceneGraph/src/osgViewer$ grep readDISPLAY */*.cpp
config/AcrossAllScreens.cpp: si.readDISPLAY();
config/PanoramicSphericalDisplay.cpp: si.readDISPLAY();
config/SingleWindow.cpp: traits->readDISPLAY();
config/SingleWindow.cpp: si.readDISPLAY();
config/SphericalDisplay.cpp: si.readDISPLAY();
config/WoWVxDisplay.cpp: si.readDISPLAY();

So I'd suggest using this, such as (modified main.cpp for osgtest:

std::cout << wsi->getNumScreens() << " screen(s) detected" << std::endl;
for ( unsigned int screen=0 ; screen <
wsi->getNumScreens(main_screen_id); screen++ )
{
osg::GraphicsContext::ScreenIdentifier screen_id(screen);
osg::GraphicsContext::ScreenSettings screen_settings;
wsi->getScreenSettings( screen_id, screen_settings );
std::cout << " Screen #" << screen << " : "
<< screen_settings.width << "x" <<
screen_settings.height << " "
<< screen_settings.refreshRate << "Hz "
<< screen_settings.colorDepth << " bit" << std::endl;
}

I have also attached the full modified file.

Robert.
Robert Osfield
2018-09-05 14:54:55 UTC
Permalink
I missed changing one of the getScreen() calls in main, so please use
the attached version.
Omar Álvarez
2018-09-05 16:06:27 UTC
Permalink
Hi Robert,

Your answer almost fixed my issue. There is just one
problem wsi->getScreenSettings(), still queries the wrong session:

1 screen(s) detected
Invalid MIT-MAGIC-COOKIE-1 keyUnable to open display ":0.1".
Screen #0 : 0x0 0Hz 0 bit

The problem is screen_id(screen), since it is not 0. The proper call would
be:

osg::GraphicsContext::ScreenIdentifier screen_id(main_screen_id.hostName,
main_screen_id.displayNum, screen);

I will update the test repo with the proper code.

Thank you very much for your time. If nobody else feels like doing it, I
can help with updating osg::GraphicsContext::WindowingSystemInterface.

Cheers,

Omar.
Post by Robert Osfield
Post by Julien Valentin
for your code you should replace
wsi->getNumScreens()
with
wsi->getNumScreens(osg::GraphicsContext::ScreenIdentifier(1))
to work on DISPLAY=:1.0
Sounds like we are getting to the bottom of things now :-)
FYI, WindowingSystemInterface::getNumScreens() is implemented in
virtual unsigned int getNumScreens(const ScreenIdentifier&
screenIdentifier = ScreenIdentifier()) = 0;
displayNum(0),
screenNum(0) {}
Which is fine if the system doesn't change the default DISPLAY from 0.0.
Support for DISPLAY is actually built into ScreenIdentifier via the
/** 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 that this parameter has not been set. When
parameters are undefined one can call
* call setUndefinedScreenDetailsToDefaultScreen() after
readDISPLAY() to ensure valid values. */
void readDISPLAY();
To is not called by the constructor though, so you need to call it
explicitly. The various Viewer config implementations do actually
~/OpenSceneGraph/src/osgViewer$ grep readDISPLAY */*.cpp
config/AcrossAllScreens.cpp: si.readDISPLAY();
config/PanoramicSphericalDisplay.cpp: si.readDISPLAY();
config/SingleWindow.cpp: traits->readDISPLAY();
config/SingleWindow.cpp: si.readDISPLAY();
config/SphericalDisplay.cpp: si.readDISPLAY();
config/WoWVxDisplay.cpp: si.readDISPLAY();
std::cout << wsi->getNumScreens() << " screen(s) detected" << std::endl;
for ( unsigned int screen=0 ; screen <
wsi->getNumScreens(main_screen_id); screen++ )
{
osg::GraphicsContext::ScreenIdentifier screen_id(screen);
osg::GraphicsContext::ScreenSettings screen_settings;
wsi->getScreenSettings( screen_id, screen_settings );
std::cout << " Screen #" << screen << " : "
<< screen_settings.width << "x" <<
screen_settings.height << " "
<< screen_settings.refreshRate << "Hz "
<< screen_settings.colorDepth << " bit" << std::endl;
}
I have also attached the full modified file.
Robert.
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Robert Osfield
2018-09-05 16:36:27 UTC
Permalink
Hi Omar,
Thank you very much for your time. If nobody else feels like doing it, I can help with updating osg::GraphicsContext::WindowingSystemInterface.
This hasn't looked like an OSG bug too me, just a usage issue. What
specifically do you think might need changing with
WindowingSystemInterface?

Robert.
Omar Álvarez
2018-09-05 16:47:20 UTC
Permalink
Sorry, I meant the samples that use it. You're right.
Post by Robert Osfield
Hi Omar,
Post by Omar Álvarez
Thank you very much for your time. If nobody else feels like doing it, I
can help with updating osg::GraphicsContext::WindowingSystemInterface.
This hasn't looked like an OSG bug too me, just a usage issue. What
specifically do you think might need changing with
WindowingSystemInterface?
Robert.
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Ravi Mathur
2018-09-06 16:16:24 UTC
Permalink
Thanks guys for figuring this out. I ran into the exact same problem
earlier this week with Ubuntu 18.04. I'm using CompositeViewer similar to
the "-3" case of the osgcompositeviewer example (multiple Views in one
window). I call osg::GraphicsContext::createGraphicsContext(traits) with my
custom Traits, and of course was getting the "Unable to open display
":0.0"" error.

Robert's suggestion of calling "traits->readDISPLAY()" before creating the
graphics context seems to have fixed it.

Ravi
Post by Omar Álvarez
Sorry, I meant the samples that use it. You're right.
Post by Robert Osfield
Hi Omar,
Post by Omar Álvarez
Thank you very much for your time. If nobody else feels like doing it,
I can help with updating osg::GraphicsContext::WindowingSystemInterface.
This hasn't looked like an OSG bug too me, just a usage issue. What
specifically do you think might need changing with
WindowingSystemInterface?
Robert.
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Julien Valentin
2018-09-05 15:05:47 UTC
Permalink
Okay that's how it works
it would be good to integrate these changes in all examples using
osg::GraphicsContext::WindowingSystemInterface
Post by Robert Osfield
I missed changing one of the getScreen() calls in main, so please use
the attached version.
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
------------------
Post generated by Mail2Forum
------------------------
Twirling twirling twirling toward freedom

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74660#74660
Robert Osfield
2018-09-05 15:32:10 UTC
Permalink
Post by Julien Valentin
Okay that's how it works
it would be good to integrate these changes in all examples using
osg::GraphicsContext::WindowingSystemInterface
That sounds like you are volunteering :-)

Robert.
Loading...