Re: [osg-users] Custom GraphicsContext Segmentation Fault when using Multithreading
Hi, so after countless more hours of debugging I have identified the issue. Within the "setUpEGL" function I already set the eglContext to be current. So once the "makeCurrentImplementation" is called, the context is already set to be current. For some reason, when using singlethreaded rendering, this works without issues and "eglMakeCurrent" returns EGL_TRUE even if the context is already active. However, when using multithreading, eglMakeCurrent fails when called on an active context and also appearantly invalidates the context, so that all following OpenGL calls fail. I managed to fix the issue completely by just removing the "eglMakeCurrent" call within my "setUpEGL" function, so that the context does not become current before "makeCurrentImplementation" is executed by OSG. I can now use the application without errors on the realtime machine. :) Thank you! Cheers, Philipp -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66995#66995 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom GraphicsContext Segmentation Fault when using Multithreading
Hi, I tried to orientate on "PixelBufferX11" when creating the EGLGraphicsContext, and I noticed that PixelBufferX11 calls the "init()" method in the constructor as well as in the "realizeImplementation" method, if necessary. So my call to "realizeImpl" in the constructor is pretty much just resembling that structure. It indeed seems like there is no graphics context when the graphics thread starts, however, I fail to understand why this only happens when in multithreading mode. I studied the PixelBufferX11 source code but couldnt find anything that would explain the error in my implementation. Unfortunately I cannot test the original GraphicsContext on my realtime machine because it cant run it, however, it works fine on my ubuntu desktop machine that I use for programming. Thank you! Cheers, Philipp -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66925#66925 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom GraphicsContext Segmentation Fault when using Multithreading
On 22 April 2016 at 09:46, Sebastian Messerschmidt < sebastian.messerschm...@gmx.de> wrote: > Hi Robert, > > He edited the original post. > > I've attached it for you. > Thanks Sebastian. I went to the forum page but it didn't appear. Do you need to be logged in to see attachments? I've had a quick look over the implementation, the only oddity I spotted was call realizeImplementation() from the constructor. This is redundant as the viewer will call GraphicsContext::realize() automatically for you when viewer.realize() is called.None of the other GraphicsContext implementations call realize in the constructor so see not reason why it should be required in this instance. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom GraphicsContext Segmentation Fault when using Multithreading
Hi Robert, He edited the original post. I've attached it for you. Cheers Sebastian Hi Phillipp, The source didn't make it through the osg-users mailing list so can't comment about the implementation side. From the error description in the first post it's clear that the graphics context is not current when the graphics thread starts running. osgViewer specifically calls makeCurrent() to ensure that the context is current, if this fails then you'd see issues like you are seeing. Whether this is the issue or not I can not say. I could see being able to create an OSG application without X11 would be useful. Any chance that you could open source the implementation and submit for inclusion with the core osgViewer? This route would help others help refine the implementation. The first step would follow would be to make an small example program with all the required classes in it then get this working, and then once it's refined enough move the GraphicsContext implementation into osgViewer to sit alongside the rest of the implementation. Cheers, Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org /* * EGLGraphicsWindow.cpp * * Created on: Apr 12, 2016 * Author: ubuntu */ #include "EGLGraphicsContext.h" #include using namespace std; EGLGraphicsContext::EGLGraphicsContext(osg::GraphicsContext::Traits* traits) : osg::GraphicsContext(), _initialized(false), eglSurface(nullptr), eglContext( nullptr) { _traits = traits; realizeImplementation(); if (valid()) { setState(new osg::State); getState()->setGraphicsContext(this); if (_traits.valid() && _traits->sharedContext.valid()) { getState()->setContextID( _traits->sharedContext->getState()->getContextID()); incrementContextIDUsageCount(getState()->getContextID()); } else { getState()->setContextID( osg::GraphicsContext::createNewContextID()); } } } EGLGraphicsContext::~EGLGraphicsContext() { // TODO Auto-generated destructor stub } /** Return whether a valid and usable GraphicsContext has been created.*/ bool EGLGraphicsContext::valid() const { return _initialized; } /** Realize the GraphicsContext implementation, * Pure virtual - must be implemented by concrete implementations of GraphicsContext. */ bool EGLGraphicsContext::realizeImplementation() { if (_initialized) { return true; } GetEglExtensionFunctionPointers(); eglDevice = GetEglDevice(); drmFd = GetDrmFd(eglDevice); SetMode(drmFd, &planeID, &width, &height); eglDpy = GetEglDisplay(eglDevice, drmFd); SetUpEgl(eglDpy, planeID, _traits->width, _traits->height, &eglSurface, &eglContext); //disable vsync if (eglSwapInterval(eglDpy, 0) == EGL_TRUE) { cout << "swap interval changed successfully." << endl; } else { cout << "error while changing swap interval" << endl; } _initialized = true; return true; } /** Return true if the graphics context has been realized, and is ready to use, implementation. * Pure virtual - must be implemented by concrete implementations of GraphicsContext. */ bool EGLGraphicsContext::isRealizedImplementation() const { return _initialized; } /** Close the graphics context implementation. * Pure virtual - must be implemented by concrete implementations of GraphicsContext. */ void EGLGraphicsContext::closeImplementation() { _initialized = false; } /** Make this graphics context current implementation. * Pure virtual - must be implemented by concrete implementations of GraphicsContext. */ bool EGLGraphicsContext::makeCurrentImplementation() { // cout << "egl context make current" << endl; // cout << "is initialized?: " << _initialized << endl; return eglMakeCurrent(eglDpy, eglSurface, eglSurface, eglContext) == EGL_TRUE; } /** Make this graphics context current with specified read context implementation. * Pure virtual - must be implemented by concrete implementations of GraphicsContext. */ bool EGLGraphicsContext::makeContextCurrentImplementation( GraphicsContext* readContext) { return makeCurrentImplementation(); } /** Release the graphics context implementation.*/ bool EGLGraphicsContext::releaseContextImplementation() { // cout << "egl context release" << endl; return eglMakeCurrent(eglDpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) == EGL_TRUE; } /** Pure virtual, Bind the graphics context to associated texture implementation. * Pure virtual - must be implemented by concrete implementations of GraphicsContext. */ void EGLGraphicsContext::bindPBufferToTextureImplementation(GLenum buffer) { cout << "bindPBuffer not impl for egl context!!" << endl; } /** Swap the front and back buffers implementation. * Pure virtual - must be implemented by
Re: [osg-users] Custom GraphicsContext Segmentation Fault when using Multithreading
Hi Phillipp, The source didn't make it through the osg-users mailing list so can't comment about the implementation side. >From the error description in the first post it's clear that the graphics context is not current when the graphics thread starts running. osgViewer specifically calls makeCurrent() to ensure that the context is current, if this fails then you'd see issues like you are seeing. Whether this is the issue or not I can not say. I could see being able to create an OSG application without X11 would be useful. Any chance that you could open source the implementation and submit for inclusion with the core osgViewer? This route would help others help refine the implementation. The first step would follow would be to make an small example program with all the required classes in it then get this working, and then once it's refined enough move the GraphicsContext implementation into osgViewer to sit alongside the rest of the implementation. Cheers, Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom GraphicsContext Segmentation Fault when using Multithreading
Hi, I added the source code for the custom graphicsContext. Sorry for the delay. Thank you! Cheers, Philipp -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66918#66918 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Custom GraphicsContext Segmentation Fault when using Multithreading
DISCLAIMER: I'm not a graphics or OpenGL expert, so if something is dumb or doesnt make sense please let me know. Hi, I am trying to use OSG to create an application for a real time Linux system without a windowing system. To get OSG to work properly, I create my own GraphicsContext and assign it to each Camera I'm using. Within the GraphicsContext I set up EGL and DRM. My GraphicsContext source code: This works fine and I can run my application perfectly on the real time machine. However, if I switch from a single threaded rendering mode to multithreaded mode, I get a segmentation fault error and I'm having trouble understanding why. I debugged the application via remote debugger and the segmentation fault happens here: Code: Shader::PerContextShader::PerContextShader(const Shader* shader, unsigned int contextID) : osg::Referenced(), _contextID( contextID ) { _shader = shader; _extensions = GLExtensions::Get( _contextID, true ); _glShaderHandle = _extensions->glCreateShader( shader->getType() ); requestCompile(); } The function ptr "glCreateShader" is set to 0x0. After double checking it seems like the method to assign the function pointers fails because no valid OpenGL context can be found. The application also prints > Error: OpenGL version test failed, requires valid graphics context. So now I'm wondering why this only happens if I enable multithreaded rendering, and not for singleThreaded rendering. What exactly do I need to change so that multithreading works on the real time machine? Thank you! Cheers, mille25 -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=66895#66895 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org