OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Segfault in osg::LightModel


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Submission
View previous topic :: View next topic  
Author Message
Christoph Weiss
Guest





PostPosted: Thu Sep 22, 2016 1:10 pm    Post subject:
Segfault in osg::LightModel
Reply with quote

Hello,

The attached patch fixes a possible segmentation fault in OSG 3.5.1 in
osg::LightModel that is triggered by glGetString() returning NULL. It's
still not really thread safe, as before, but safe enough.

--
Mit freundlichen Grüßen,

Christoph Weiß

WSoptics GmbH
Only registered users can see emails on this board!
Get registred or enter the forums!

+49 8868 181 997 3
Zugspitzstraße 9
86972 Altenstadt

HRB 204558 Gerichtsstand: München B Ust.Id.Nr.: DE289079930
Geschäftsführer: Florian Sepp, Dr. Christoph Weiß



------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10799

PostPosted: Thu Sep 22, 2016 1:40 pm    Post subject:
Segfault in osg::LightModel
Reply with quote

Hi Christoph,

I reviewed your changes but fee there is a safe way to do this. The
use of local static variable isn't safe so I've replaced the static
code with state.get<GLExtensions> usage that is thread-safe and
multi-context friendly. Changes are outlined below. These are now
checked into the git master and OSG-3.4 branch.

A wider question I'd have though is what glGet("GL_VERSION") is
failing for you. What GL driver and platform are you using?

Robert.

diff --git a/src/osg/LightModel.cpp b/src/osg/LightModel.cpp
index 41c4acc..6617e5d 100644
--- a/src/osg/LightModel.cpp
+++ b/src/osg/LightModel.cpp
@@ -16,6 +16,7 @@
#include <osg/GL>
#include <osg/LightModel>
#include <osg/Notify>
+#include <osg/State>

using namespace osg;

@@ -34,6 +35,8 @@ LightModel::~LightModel()
{
}

+#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
+
// need to define if gl.h version < 1.2.
#ifndef GL_LIGHT_MODEL_COLOR_CONTROL
#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
@@ -47,10 +50,8 @@ LightModel::~LightModel()
#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
#endif

-
-void LightModel::apply(State&) const
+void LightModel::apply(State& state) const
{
-#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE

#ifdef OSG_GLES1_AVAILABLE
#define glLightModeli glLightModelx
@@ -58,8 +59,7 @@ void LightModel::apply(State&) const

glLightModelfv(GL_LIGHT_MODEL_AMBIENT,_ambient.ptr());

- static bool s_separateSpecularSupported = strncmp((const
char*)glGetString(GL_VERSION),"1.2",3)>=0;
- if (s_separateSpecularSupported)
+ if (state.get<GLExtensions>()->glVersion>=1.2)
{
if (_colorControl==SEPARATE_SPECULAR_COLOR)
{
@@ -76,8 +76,14 @@ void LightModel::apply(State&) const
#endif

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_twoSided);
+}
+
#else
+
+void LightModel::apply(State&) const
+{
OSG_NOTICE<<"Warning: LightModel::apply(State&) - not
supported."<<std::endl;
-#endif
}

On 22 September 2016 at 14:09, Christoph Weiss <> wrote:
Quote:
Hello,

The attached patch fixes a possible segmentation fault in OSG 3.5.1 in
osg::LightModel that is triggered by glGetString() returning NULL. It's
still not really thread safe, as before, but safe enough.

--
Mit freundlichen Grüßen,

Christoph Weiß

WSoptics GmbH

+49 8868 181 997 3
Zugspitzstraße 9
86972 Altenstadt

HRB 204558 Gerichtsstand: München B Ust.Id.Nr.: DE289079930
Geschäftsführer: Florian Sepp, Dr. Christoph Weiß





------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Christoph Weiss
Guest





PostPosted: Thu Sep 22, 2016 2:00 pm    Post subject:
Segfault in osg::LightModel
Reply with quote

Hi Robert,

Thank you for the quick reply and fix!

As for the reasons, I'm uncertain. Our application only works in
SingleThreaded mode, otherwise it produces "Error: OpenGL version test
failed, requires valid graphics context."

I'll let you know when I find what causes this.

Christoph

Mit freundlichen Grüßen,

Christoph Weiß

WSoptics GmbH

+49 8868 181 997 3
Zugspitzstraße 9
86972 Altenstadt

HRB 204558 Gerichtsstand: München B Ust.Id.Nr.: DE289079930
Geschäftsführer: Florian Sepp, Dr. Christoph Weiß

On 09/22/2016 03:38 PM, Robert Osfield wrote:
Quote:
Hi Christoph,

I reviewed your changes but fee there is a safe way to do this. The
use of local static variable isn't safe so I've replaced the static
code with state.get<GLExtensions> usage that is thread-safe and
multi-context friendly. Changes are outlined below. These are now
checked into the git master and OSG-3.4 branch.

A wider question I'd have though is what glGet("GL_VERSION") is
failing for you. What GL driver and platform are you using?

Robert.

diff --git a/src/osg/LightModel.cpp b/src/osg/LightModel.cpp
index 41c4acc..6617e5d 100644
--- a/src/osg/LightModel.cpp
+++ b/src/osg/LightModel.cpp
@@ -16,6 +16,7 @@
#include <osg/GL>
#include <osg/LightModel>
#include <osg/Notify>
+#include <osg/State>

using namespace osg;

@@ -34,6 +35,8 @@ LightModel::~LightModel()
{
}

+#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
+
// need to define if gl.h version < 1.2.
#ifndef GL_LIGHT_MODEL_COLOR_CONTROL
#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
@@ -47,10 +50,8 @@ LightModel::~LightModel()
#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
#endif

-
-void LightModel::apply(State&) const
+void LightModel::apply(State& state) const
{
-#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE

#ifdef OSG_GLES1_AVAILABLE
#define glLightModeli glLightModelx
@@ -58,8 +59,7 @@ void LightModel::apply(State&) const

glLightModelfv(GL_LIGHT_MODEL_AMBIENT,_ambient.ptr());

- static bool s_separateSpecularSupported = strncmp((const
char*)glGetString(GL_VERSION),"1.2",3)>=0;
- if (s_separateSpecularSupported)
+ if (state.get<GLExtensions>()->glVersion>=1.2)
{
if (_colorControl==SEPARATE_SPECULAR_COLOR)
{
@@ -76,8 +76,14 @@ void LightModel::apply(State&) const
#endif

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_twoSided);
+}
+
#else
+
+void LightModel::apply(State&) const
+{
OSG_NOTICE<<"Warning: LightModel::apply(State&) - not
supported."<<std::endl;
-#endif
}

On 22 September 2016 at 14:09, Christoph Weiss <> wrote:
Quote:
Hello,

The attached patch fixes a possible segmentation fault in OSG 3.5.1 in
osg::LightModel that is triggered by glGetString() returning NULL. It's
still not really thread safe, as before, but safe enough.

--
Mit freundlichen Grüßen,

Christoph Weiß

WSoptics GmbH

+49 8868 181 997 3
Zugspitzstraße 9
86972 Altenstadt

HRB 204558 Gerichtsstand: München B Ust.Id.Nr.: DE289079930
Geschäftsführer: Florian Sepp, Dr. Christoph Weiß







------------------
Post generated by Mail2Forum
Back to top
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10799

PostPosted: Thu Sep 22, 2016 2:22 pm    Post subject:
Segfault in osg::LightModel
Reply with quote

On 22 September 2016 at 14:59, Christoph Weiss <> wrote:
Quote:
As for the reasons, I'm uncertain. Our application only works in
SingleThreaded mode, otherwise it produces "Error: OpenGL version test
failed, requires valid graphics context."

I'll let you know when I find what causes this.

Sounds like a rendering traversal has been kicked off from a thread
that doesn't yet have a graphics context current.

Discussion about these types of issues are best done on the osg-users
mailing list/forum.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Submission All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts getGraphicsContext()/getState() segfa... Valtiel General 4 Fri Nov 25, 2016 4:52 pm View latest post
No new posts Segfault when using addChild on Group... andrezsanchez General 4 Fri Apr 22, 2016 4:33 pm View latest post
No new posts Segfault occuring in -- void Text::dr... crubel@compro.net General 19 Wed Apr 29, 2015 9:02 pm View latest post
No new posts model.ive from 3.15 to load with 3.20... Trajce Nikolov NICK General 0 Wed Aug 28, 2013 12:27 pm View latest post
No new posts Segfault with Qt Tiziano Müller General 9 Sat Oct 22, 2011 1:09 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP