osgearth icon indicating copy to clipboard operation
osgearth copied to clipboard

3.3: stack smashing detected

Open elbarto1980 opened this issue 1 year ago • 2 comments

Hi, I have just upgraded osgearth-3.2 to the 3.3 release. It has been compiled and built using cmake without any issues but when I run any of the utils in build/bin I got the following message (and it crashes):

❯ ../build/bin/osgearth_viewer boston.earth ObjectWrapperManager::addWrapper(): 'osg::DummyObject' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::ClampableNode' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::InstallCameraUniform' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::DrapeableNode' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::Util::DrawInstanced::InstanceGeometry' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::StringObject' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::LightGL3' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::MaterialGL3' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::LineGroup' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::LineDrawable' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::PointGroup' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::PointDrawable' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::Text' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::TextureBuffer' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::VirtualProgram' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::FeatureSourceIndexNode' already exists. ObjectWrapperManager::addWrapper(): 'osgEarth::PlaceNode' already exists. *** stack smashing detected ***: terminated zsh: abort ../build/bin/osgearth_viewer boston.earth

The code that I developed using the libraries crashes as well... Is it already a known issue? Does it have a quick fix?

I ran "osgearth_version --caps" to provide some helpful (I hope) insights about my setup. Here's the output:

[osgEarth] [Registry] Note: GDAL_DATA environment variable is not set [osgEarth] [Capabilities] Capabilities: [osgEarth] [Capabilities] osgEarth Version: 3.3.0 build 135 [osgEarth] [Capabilities] OSG Version: 3.6.5 [osgEarth] [Capabilities] GDAL Version: 3.0.4 [osgEarth] [Capabilities] GEOS Version: 3.8.0 [osgEarth] [Capabilities] GPU Vendor: NVIDIA Corporation [osgEarth] [Capabilities] GPU Renderer: NVIDIA GeForce RTX 3070 Laptop GPU/PCIe/SSE2 [osgEarth] [Capabilities] GL/Driver Version: 4.6.0 NVIDIA 515.65.01 (460) [osgEarth] [Capabilities] GL Core Profile: no

Thank you very much for your help!

elbarto1980 avatar Aug 06 '22 13:08 elbarto1980

Did you do a full clean rebuild and delete any old files you have laying around?

jasonbeverage avatar Aug 08 '22 15:08 jasonbeverage

Hi, Thank you for your reply. I have just cleaned and rebuilt everything and I have managed to make osgearth_viewer work again (there were probably some old files inside the system directories that I missed before).

Then I moved to try and rebuild my code. It is built without errors and warnings but when I run it, I get a very long list of messages that end up with a segmentation fault. Here's the output:

VERTEX glCompileShader "main(vertex)" FAILED VERTEX Shader "main(vertex)" infolog: 0(26) : error C7616: global variable gl_Vertex is removed after version 140 0(27) : error C7616: global variable gl_Normal is removed after version 140 0(28) : error C7616: global variable gl_Color is removed after version 140 0(29) : error C7616: global variable gl_ModelViewMatrix is removed after version 140 0(30) : error C7616: global variable gl_ModelViewProjectionMatrix is removed after version 140 0(31) : error C7616: global variable gl_NormalMatrix is removed after version 140

glLinkProgram 0x564e91492dc0"SimpleSky Stars" FAILED Program "SimpleSky Stars" infolog: Vertex info

0(26) : error C7616: global variable gl_Vertex is removed after version 140 0(27) : error C7616: global variable gl_Normal is removed after version 140 0(28) : error C7616: global variable gl_Color is removed after version 140 0(29) : error C7616: global variable gl_ModelViewMatrix is removed after version 140 0(30) : error C7616: global variable gl_ModelViewProjectionMatrix is removed after version 140 0(31) : error C7616: global variable gl_NormalMatrix is removed after version 140 (0) : error C2003: incompatible options for link

[osgEarth]* [VirtualProgram] Program will not link! [osgEarth]* SHADER main(vertex) infolog errors: 0: #version 460 1: #extension GL_ARB_gpu_shader_int64 : enable 2: #pragma vp_name VP Vertex Shader Main 3: // Vertex stage globals: 4: float oe_Stars_visibility; 5: vec3 vp_Normal; 6: vec3 vp_VertexView; 7: vec4 vp_Color; 8: vec4 vp_Vertex; 9: // Vertex stage outputs: 10: out VP_PerVertex { 11: float oe_Stars_visibility; 12: vec3 vp_Normal; 13: vec3 vp_VertexView; 14: vec4 vp_Color; 15: vec4 vp_Vertex; 16: } vp_out; 17: // Function declarations: 18: void oe_Stars_VS(inout vec4); 19: void main(void) 20: { 21: vp_Vertex = gl_Vertex; 22: vp_Normal = gl_Normal; 23: vp_Color = gl_Color; 24: vp_VertexView = (gl_ModelViewMatrix * vp_Vertex).xyz; 25: vp_Vertex = gl_ModelViewProjectionMatrix * vp_Vertex; 26**> vp_Normal = normalize(gl_NormalMatrix * vp_Normal); 27: oe_Stars_VS(vp_Vertex); 28: gl_Position = vp_Vertex; 29: vp_out.oe_Stars_visibility = oe_Stars_visibility; 30: vp_out.vp_Normal = vp_Normal; 31: vp_out.vp_VertexView = vp_VertexView; 32: vp_out.vp_Color = vp_Color; 33: vp_out.vp_Vertex = vp_Vertex; 34: }

VERTEX glCompileShader "atmos_vertex_main" FAILED VERTEX Shader "atmos_vertex_main" infolog: 0(53) : error C7616: global variable gl_Vertex is removed after version 140

FRAGMENT glCompileShader "atmos_fragment_main" FAILED FRAGMENT Shader "atmos_fragment_main" infolog: 0(22) : error C7616: global variable gl_ProjectionMatrix is removed after version 140

VERTEX glCompileShader "main(vertex)" FAILED VERTEX Shader "main(vertex)" infolog: 0(32) : error C7616: global variable gl_Vertex is removed after version 140 0(33) : error C7616: global variable gl_Normal is removed after version 140 0(34) : error C7616: global variable gl_Color is removed after version 140 0(35) : error C7616: global variable gl_ModelViewMatrix is removed after version 140 0(36) : error C7616: global variable gl_NormalMatrix is removed after version 140 0(39) : error C7616: global variable gl_ProjectionMatrix is removed after version 140

glLinkProgram 0x564e916158d0"SimpleSky Atmosphere" FAILED Program "SimpleSky Atmosphere" infolog: Vertex info

0(53) : error C7616: global variable gl_Vertex is removed after version 140 (0) : error C2003: incompatible options for link 0(32) : error C7616: global variable gl_Vertex is removed after version 140 0(33) : error C7616: global variable gl_Normal is removed after version 140 0(34) : error C7616: global variable gl_Color is removed after version 140 0(35) : error C7616: global variable gl_ModelViewMatrix is removed after version 140 0(36) : error C7616: global variable gl_NormalMatrix is removed after version 140 0(39) : error C7616: global variable gl_ProjectionMatrix is removed after version 140 (0) : error C2003: incompatible options for link

Fragment info

0(22) : error C7616: global variable gl_ProjectionMatrix is removed after version 140 (0) : error C2003: incompatible options for link

[osgEarth]* [VirtualProgram] Program will not link! [osgEarth]* SHADER atmos_vertex_main infolog errors: 0: #version 460 1: #extension GL_ARB_gpu_shader_int64 : enable 2: #pragma vp_function atmos_vertex_main, vertex_view, 0.5 3: #define VP_STAGE_VERTEX 4: // Atmospheric Scattering and Sun Shaders 5: // Adapted from code that is Copyright (c) 2004 Sean ONeil 6: uniform mat4 osg_ViewMatrixInverse; 7: // camera position in [3].xyz 8: uniform vec3 atmos_v3LightDir; 9: // The direction vector to the light source 10: uniform float atmos_fOuterRadius; 11: // Outer atmosphere radius 12: uniform float atmos_fInnerRadius; 13: // Inner planetary radius 14: const float PI = 3.1415927; 15: const float Kr = 0.0025; 16: const float Km = 0.0015; 17: const float ESun = 15.0; 18: const float RaleighScaleDepth = 0.25; 19: const float atmos_fKrESun = Kr * ESun; 20: const float atmos_fKmESun = Km * ESun; 21: const float atmos_fKr4PI = Kr * 4 * PI; 22: const float atmos_fKm4PI = Km * 4 * PI; 23: const vec3 atmos_v3InvWavelength = vec3(5.6020447, 9.4732844, 19.6438026); 24: #define N_SAMPLES 2 25: #define F_SAMPLES 2.0 26: float atmos_fCameraHeight; 27: float atmos_fCameraHeight2; 28: float atmos_fOuterRadius2; 29: float atmos_fScale; 30: float atmos_fScaleOverScaleDepth; 31: vec3 atmos_vVec; 32: vec3 atmos_v3Direction; 33: #pragma vp_varying_out vec3 atmos_v3Direction 34: vec3 atmos_mieColor; 35: #pragma vp_varying_out vec3 atmos_mieColor 36: vec3 atmos_rayleighColor; 37: #pragma vp_varying_out vec3 atmos_rayleighColor 38: float atmos_renderFromSpace; 39: #pragma vp_varying_out float atmos_renderFromSpace 40: float atmos_fastpow(in float x, in float y) 41: { 42: return x/(x+y-yx); 43: } 44: float atmos_scale(float fCos) 45: { 46: float x = 1.0 - fCos; 47: return RaleighScaleDepth * exp(-0.00287 + x(0.459 + x*(3.83 + x*(-6.80 + x5.25)))); 48: } 49: void atmos_SkyFromSpace(void) 50: { 51: // Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere) 52: vec3 v3Pos = gl_Vertex.xyz; 53**> vec3 v3Ray = v3Pos - atmos_vVec; 54: float fFar = length(v3Ray); 55: v3Ray /= fFar; 56: // Calculate the closest intersection of the ray with the outer atmosphere 57: // (which is the near point of the ray passing through the atmosphere) 58: float B = 2.0 * dot(atmos_vVec, v3Ray); 59: float C = atmos_fCameraHeight2 - atmos_fOuterRadius2; 60: float fDet = max(0.0, BB - 4.0 * C); 61: float fNear = 0.5 * (-B - sqrt(fDet)); 62: // Calculate the ray's starting position, then calculate its scattering offset 63: vec3 v3Start = atmos_vVec + v3Ray * fNear; 64: fFar -= fNear; 65: float fStartAngle = dot(v3Ray, v3Start) / atmos_fOuterRadius; 66: float fStartDepth = exp(-1.0 / RaleighScaleDepth); 67: float fStartOffset = fStartDepthatmos_scale(fStartAngle); 68: // Initialize the atmos_ing loop variables 69: float fSampleLength = fFar / F_SAMPLES; 70: float fScaledLength = fSampleLength * atmos_fScale; 71: vec3 v3SampleRay = v3Ray * fSampleLength; 72: vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5; 73: // Now loop through the sample rays 74: vec3 v3FrontColor = vec3(0.0, 0.0, 0.0); 75: vec3 v3Attenuate;
76: for(int i=0; i<N_SAMPLES; i++) 77: { 78: float fHeight = length(v3SamplePoint); 79: float fDepth = exp(atmos_fScaleOverScaleDepth * (atmos_fInnerRadius - fHeight)); 80: float fLightAngle = dot(atmos_v3LightDir, v3SamplePoint) / fHeight; 81: float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight; 82: float fscatter = (fStartOffset + fDepth
(atmos_scale(fLightAngle) - atmos_scale(fCameraAngle))); 83: v3Attenuate = exp(-fscatter * (atmos_v3InvWavelength * atmos_fKr4PI + atmos_fKm4PI)); 84: v3FrontColor += v3Attenuate * (fDepth * fScaledLength); 85: v3SamplePoint += v3SampleRay; 86: } 87: // Finally, scale the Mie and Rayleigh colors and set up the varying 88: // variables for the pixel shader 89: atmos_mieColor = v3FrontColor * atmos_fKmESun; 90: atmos_rayleighColor = v3FrontColor * (atmos_v3InvWavelength * atmos_fKrESun); 91: atmos_v3Direction = atmos_vVec - v3Pos; 92: } 93: void atmos_SkyFromAtmosphere(void) 94: { 95: // Get the ray from the camera to the vertex, and its length (which is the far 96: // point of the ray passing through the atmosphere) 97: vec3 v3Pos = gl_Vertex.xyz; 98: vec3 v3Ray = v3Pos - atmos_vVec; 99: float fFar = length(v3Ray); 100: v3Ray /= fFar; 101: // Calculate the ray's starting position, then calculate its atmos_ing offset 102: vec3 v3Start = atmos_vVec; 103: float fHeight = length(v3Start); 104: float fDepth = exp(atmos_fScaleOverScaleDepth * (atmos_fInnerRadius - atmos_fCameraHeight)); 105: float fStartAngle = dot(v3Ray, v3Start) / fHeight; 106: float fStartOffset = fDepthatmos_scale(fStartAngle); 107: // Initialize the atmos_ing loop variables 108: float fSampleLength = fFar / F_SAMPLES; 109: float fScaledLength = fSampleLength * atmos_fScale; 110: vec3 v3SampleRay = v3Ray * fSampleLength; 111: vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5; 112: // Now loop through the sample rays 113: vec3 v3FrontColor = vec3(0.0, 0.0, 0.0); 114: vec3 v3Attenuate;
115: for(int i=0; i<N_SAMPLES; i++) 116: { 117: float fHeight = length(v3SamplePoint); 118: float fDepth = exp(atmos_fScaleOverScaleDepth * (atmos_fInnerRadius - fHeight)); 119: float fLightAngle = dot(atmos_v3LightDir, v3SamplePoint) / fHeight; 120: float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight; 121: float fscatter = (fStartOffset + fDepth
(atmos_scale(fLightAngle) - atmos_scale(fCameraAngle))); 122: v3Attenuate = exp(-fscatter * (atmos_v3InvWavelength * atmos_fKr4PI + atmos_fKm4PI)); 123: v3FrontColor += v3Attenuate * (fDepth * fScaledLength); 124: v3SamplePoint += v3SampleRay; 125: } 126: // Finally, scale the Mie and Rayleigh colors and set up the varying 127: // variables for the pixel shader 128: atmos_mieColor = v3FrontColor * atmos_fKmESun; 129: atmos_rayleighColor = v3FrontColor * (atmos_v3InvWavelength * atmos_fKrESun); 130: atmos_v3Direction = atmos_vVec - v3Pos; 131: } 132: void atmos_vertex_main(inout vec4 VertexVIEW) 133: { 134: // Get camera position and height 135: atmos_vVec = osg_ViewMatrixInverse[3].xyz; 136: atmos_fCameraHeight = length(atmos_vVec); 137: atmos_fCameraHeight2 = atmos_fCameraHeight * atmos_fCameraHeight; 138: atmos_fOuterRadius2 = atmos_fOuterRadius * atmos_fOuterRadius; 139: atmos_fScale = 1.0 / (atmos_fOuterRadius - atmos_fInnerRadius); 140: atmos_fScaleOverScaleDepth = atmos_fScale / RaleighScaleDepth; 141: if(atmos_fCameraHeight >= atmos_fOuterRadius) 142: { 143: atmos_SkyFromSpace(); 144: //atmos_renderFromSpace = 1.0; 145: } 146: else 147: { 148: atmos_SkyFromAtmosphere(); 149: //atmos_renderFromSpace = 0.0; 150: } 151: // Transition from space to atmosphere 152: atmos_renderFromSpace = 1.0 - clamp( 153: (atmos_fOuterRadius-atmos_fCameraHeight) * atmos_fScale, 154: 0.0, 1.0 ); 155: }

VERTEX glCompileShader "oe_rex_init_model" FAILED VERTEX Shader "oe_rex_init_model" infolog: 0(25) : error C7616: global variable gl_MultiTexCoord0 is removed after version 140

VERTEX glCompileShader "oe_rex_normalMapVS" FAILED VERTEX Shader "oe_rex_normalMapVS" infolog: 0(36) : error C7616: global variable gl_NormalMatrix is removed after version 140

VERTEX glCompileShader "oe_rex_morph" FAILED VERTEX Shader "oe_rex_morph" infolog: 0(93) : error C7616: global variable gl_ModelViewMatrix is removed after version 140 0(123) : error C7616: global variable gl_MultiTexCoord1 is removed after version 140 0(124) : error C7616: global variable gl_MultiTexCoord2 is removed after version 140

VERTEX glCompileShader "main(vertex)" FAILED VERTEX Shader "main(vertex)" infolog: 0(60) : error C7616: global variable gl_Vertex is removed after version 140 0(61) : error C7616: global variable gl_Normal is removed after version 140 0(62) : error C7616: global variable gl_Color is removed after version 140 0(66) : error C7616: global variable gl_ModelViewMatrix is removed after version 140 0(67) : error C7616: global variable gl_NormalMatrix is removed after version 140 0(75) : error C7616: global variable gl_ProjectionMatrix is removed after version 140

glLinkProgram 0x564e8ee92980"CompositeImageLayer" FAILED Program "CompositeImageLayer" infolog: Vertex info

0(25) : error C7616: global variable gl_MultiTexCoord0 is removed after version 140 (0) : error C2003: incompatible options for link 0(36) : error C7616: global variable gl_NormalMatrix is removed after version 140 (0) : error C2003: incompatible options for link 0(93) : error C7616: global variable gl_ModelViewMatrix is removed after version 140 0(123) : error C7616: global variable gl_MultiTexCoord1 is removed after version 140 0(124) : error C7616: global variable gl_MultiTexCoord2 is removed after version 140 (0) : error C2003: incompatible options for link 0(60) : error C7616: global variable gl_Vertex is removed after version 140 0(61) : error C7616: global variable gl_Normal is removed after version 140 0(62) : error C7616: global variable gl_Color is removed after version 140 0(66) : error C7616: global variable gl_ModelViewMatrix is removed after version 140 0(67) : error C7616: global variable gl_NormalMatrix is removed after version 140 0(75) : error C7616: global variable gl_ProjectionMatrix is removed after version 140 (0) : error C2003: incompatible options for link

[osgEarth]* [VirtualProgram] Program will not link! [osgEarth]* SHADER oe_rex_init_model infolog errors: 0: #version 460 1: #extension GL_ARB_gpu_shader_int64 : enable 2: #pragma vp_name REX Engine - Init Model Space 3: #pragma vp_function oe_rex_init_model, vertex_model, first 4: #define VP_STAGE_VERTEX 5: // uniforms 6: uniform vec4 oe_terrain_color; 7: uniform vec4 oe_tile_key_u; 8: // outputs 9: vec4 vp_Color; 10: #pragma vp_varying_out vec4 vp_Color 11: vec4 oe_layer_tilec; 12: #pragma vp_varying_out vec4 oe_layer_tilec 13: vec4 oe_terrain_tessLevel; 14: #pragma vp_varying_out vec4 oe_terrain_tessLevel 15: float oe_rex_morphFactor; 16: #pragma vp_varying_out float oe_rex_morphFactor 17: int oe_terrain_vertexMarker; 18: #pragma vp_varying_out flat int oe_terrain_vertexMarker 19: // stage globals 20: vec4 oe_tile_key; 21: void oe_rex_init_model(inout vec4 vertexModel) 22: { 23: // Texture coordinate for the tile (always 0..1) 24: oe_layer_tilec = gl_MultiTexCoord0; 25**> // Extract the vertex type marker 26: oe_terrain_vertexMarker = int(oe_layer_tilec.z); 27: // Color of the underlying map geometry (untextured) 28: vp_Color = oe_terrain_color; 29: // initialize: 30: oe_rex_morphFactor = 0.0; 31: // tile key 32: oe_tile_key = oe_tile_key_u; 33:
34: // Default tessellation level (where applicable) 35: oe_terrain_tessLevel = vec4(1); 36: }

zsh: segmentation fault

elbarto1980 avatar Aug 08 '22 16:08 elbarto1980

These errors are usually due to not having a GL3-enabled version of OpenSceneGraph. (http://docs.osgearth.org/en/latest/faq.html#runtime)

gwaldron avatar Aug 18 '22 14:08 gwaldron

Hi Glenn, thank you for your reply. I have been looking for a possible fix since I opened this issue and yesterday I began suspecting that it was related to GL3. Since then, I have already tried several CMake configurations (I found a few in the OSG forum and on the Internet) to build OpenSceneGraph with support for OpenGL 3+ but none of them work on my laptop (I noticed that I only have a "/usr/include/GLES3/gl3.h" include file in my laptop's filesystem. Should I have a GL3 directory as well?).

Anyway, setting the flag OSG_GL3_AVAILABLE=ON, I can build OSG without errors but when I run osgViewer to view the 'cow.osgt' 3D model, I have an empty OSG blue screen, without any model, and a lot of 'invalid operation' warnings in the terminal... I am copying and pasting just a few lines:

Warning: detected OpenGL error 'invalid operation' at after drawable.compileGLObjects() call in GLObjectsVisitor::apply(osg::Drawable& drawable)  
Warning: detected OpenGL error 'invalid operation' at after RenderBin::draw(..)
Warning: detected OpenGL error 'invalid operation' at end of SceneView::draw()
Warning: detected OpenGL error 'invalid operation' at start of State::apply(StateSet*)
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xc60
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xc61
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xde1
Warning: detected OpenGL error 'invalid operation' after applying attribute TexGen 0x55f76bc64410
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0xb50
Warning: detected OpenGL error 'invalid enumerant' after applying GLMode 0x4000
Warning: detected OpenGL error 'invalid operation' after applying attribute Material 0x55f76bc588b0

I know that I am going out of scope because it is a OSG-related question but do you have any idea about what I am doing wrong? The NVIDIA drivers that I have installed are from the Ubuntu 20.04 NVIDIA drivers metapackage (Software & Updates, Additional Drivers). Hopefully, they should be complete...

Could it be easier if I use vcpkg to install OSG and osgEarth?

Thank you again!


Brief update

I used the guide you posted here and now I can see a completely black cow and other warnings:

❯ ./osgviewer ../../../OpenSceneGraph-Data/cow.osgt
Warning: TexGen::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexGen::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexGen::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexGen::apply(State&) - not supported.

elbarto1980 avatar Aug 18 '22 15:08 elbarto1980

Short answer is yes: it would be much easier to install everything from vcpkg :)

The "not supported" warnings are because TexGen, Material, et al. are old GL fixed-function pipeline (FFP) mechanisms, and GL3 and osgEarth do not support FFP. (see the OSG_GL_FIXED_FUNCTION_AVAILABLE flag disabled in cmake).

Instead osgEarth relies on shaders (and shader generation). You can run the shader generator on the command line like so:

osgviewer cow.osgt.osgearth_shadergen -l osgearth

You'll still get the TexGen warnings, but at least the cow will look right.

gwaldron avatar Aug 18 '22 17:08 gwaldron

Thank you! I removed all the old files and now I am going to try with vcpkg. I think it will take some time to download and rebuild everything...

elbarto1980 avatar Aug 19 '22 11:08 elbarto1980

Yes, it takes a good while the first time, but after that everything is cached and it's fast :) Good luck.

gwaldron avatar Aug 19 '22 12:08 gwaldron

Something is still missing. I followed these guidelines (The documentation here is focused on Windows, I am building osgEarth for Ubuntu 20.04).

It looks like gdal and openjpeg have been downloaded by vcpkg, but I get an undefined reference error

❯ ./vcpkg/vcpkg list | grep gdal
gdal:x64-linux                                     3.5.1#5          The Geographic Data Abstraction Library for read...
gdal[curl]:x64-linux                                                Enable CURL network support
gdal[default-features]:x64-linux                                    Default set of features, including recommended f...
gdal[geos]:x64-linux                                                Enable GEOS support
gdal[hdf5]:x64-linux                                                Enable HDF5 support
gdal[libspatialite]:x64-linux                                       Create or update SpatiaLite databases using libs...
gdal[netcdf]:x64-linux                                              Enable NetCDF support
gdal[postgresql]:x64-linux                                          Enable PostgreSQL support
gdal[recommended-features]:x64-linux                                Features that are explicity marked as recommende...

❯ ./vcpkg/vcpkg list | grep openjpeg
openjpeg:x64-linux                                 2.5.0            OpenJPEG is an open-source JPEG 2000 codec writt...
[ 52%] Building CXX object src/osgEarth/CMakeFiles/osgEarth.dir/glyphs.pb.cc.o
[ 53%] Linking CXX shared library ../../lib/libosgEarth.so
/usr/bin/ld: ../../vcpkg_installed/x64-linux/lib/libgdal.a(openjpegdataset.o): in function `JP2OpenJPEGDataset::ReadBlock(int, _IO_FILE*, int, int, void*, int, int*)':
openjpegdataset.cpp:(.text+0x7be): undefined reference to `opj_create_decompress'
/usr/bin/ld: openjpegdataset.cpp:(.text+0x7dd): undefined reference to `opj_set_info_handler'
/usr/bin/ld: openjpegdataset.cpp:(.text+0x7f0): undefined reference to `opj_set_warning_handler'
/usr/bin/ld: openjpegdataset.cpp:(.text+0x803): undefined reference to `opj_set_error_handler'
...
/usr/bin/ld: ../../lib/libosgEarth.so.3.3.0: hidden symbol `opj_create_compress' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [src/osgEarth/CMakeFiles/osgEarth.dir/build.make:4918: lib/libosgEarth.so.3.3.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:1657: src/osgEarth/CMakeFiles/osgEarth.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

Any ideas?

elbarto1980 avatar Aug 19 '22 15:08 elbarto1980

Hmm. Just a guess but this seems like a possible build issue with GDAL; you might try using an older version of GDAL like 3.4.2 (for example; that's what I am using on Windows) and see if it works. Do do this just edit the vcpkg.json file and specify an override, as show here: https://github.com/microsoft/vcpkg/issues/21357#issuecomment-1094153309

Good luck and let me know if that works.

gwaldron avatar Aug 22 '22 16:08 gwaldron

I went from "Wow, vcpkg is so cool!" to "I really hate vcpkg!" just in a couple of days :sweat_smile:... but I will keep trying to make it work and I'll let you know. Thank you! :+1:


Update: I added the override to select the version for GDAL (cmake prints -- Found GDAL 3.4.2), unfortunately, the final outcome is still the same:

❯ cmake -S osgearth-3.3 -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=~/OSG/osgearth-3.3 -DCMAKE_TOOLCHAIN_FILE=~/gitrepo/vcpkg/scripts/buildsystems/vcpkg.cmake
-- Running vcpkg install
-- Running vcpkg install - done
CMake Warning (dev) at /usr/share/cmake-3.16/Modules/FindOpenGL.cmake:275 (message):
  Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
  available.  Run "cmake --help-policy CMP0072" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  FindOpenGL found both a legacy GL library:

    OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so

  and GLVND libraries for OpenGL and GLX:

    OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so
    OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so

  OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for
  compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
  /home/emanuele/gitrepo/vcpkg/scripts/buildsystems/vcpkg.cmake:826 (_find_package)
  CMakeLists.txt:129 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Submodule update
-- Found OpenSSL: /home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libcrypto.a (Required is at least version "3")  
-- Found ZLIB: optimized;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libz.a;debug;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/debug/lib/libz.a (found suitable version "1.2.12", minimum required is "1") 
-- Found ZLIB: optimized;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libz.a;debug;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/debug/lib/libz.a (found version "1.2.12") 
-- Found ZLIB: optimized;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libz.a;debug;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/debug/lib/libz.a (found suitable version "1.2.12", minimum required is "1") 
-- Reading /home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/share/GeoTIFF/geotiff-config.cmake
-- GeoTIFF configuration, version 1.7.1
--   include directory: ${GeoTIFF_INCLUDE_DIRS}
--   ${GeoTIFF_LIBRARIES} set to static libraries
-- Found ZLIB: optimized;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libz.a;debug;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/debug/lib/libz.a (found version "1.2.12") 
-- Found OpenSSL: /home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libcrypto.a   
-- Found OpenSSL: /home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libcrypto.a (Required is at least version "3")  
-- Found ZLIB: optimized;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libz.a;debug;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/debug/lib/libz.a (found suitable version "1.2.12", minimum required is "1") 
-- Found ZLIB: optimized;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libz.a;debug;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/debug/lib/libz.a (found version "1.2.12") 
-- Found ZLIB: optimized;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libz.a;debug;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/debug/lib/libz.a (found suitable version "1.2.12", minimum required is "1") 
-- Found ZLIB: optimized;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libz.a;debug;/home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/debug/lib/libz.a (found version "1.2.12") 
-- Found OpenSSL: /home/emanuele/gitrepo/build/vcpkg_installed/x64-linux/lib/libcrypto.a   
-- Found GDAL 3.4.2
-- Found OSG version 3.6.5
-- Creating /home/emanuele/gitrepo/build/build_include/osgEarth/BuildConfig.h
CMake Warning at /home/emanuele/gitrepo/vcpkg/scripts/buildsystems/vcpkg.cmake:826 (_find_package):
  By not providing "Findgit.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "git", but
  CMake did not find one.

  Could not find a package configuration file provided by "git" with any of
  the following names:

    gitConfig.cmake
    git-config.cmake

  Add the installation prefix of "git" to CMAKE_PREFIX_PATH or set "git_DIR"
  to a directory containing one of the above files.  If "git" provides a
  separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
  src/osgEarth/CMakeLists.txt:506 (find_package)


-- Building osgEarth as a SHARED library
-- INCDIR: /home/emanuele/OSG/osgearth-3.3/include
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_TOOLCHAIN_FILE


-- Build files have been written to: /home/emanuele/gitrepo/build

❯ cmake --build build --target install --config RelWithDebInfo
...
[ 52%] Building CXX object src/osgEarth/CMakeFiles/osgEarth.dir/glyphs.pb.cc.o
[ 53%] Linking CXX shared library ../../lib/libosgEarth.so
/usr/bin/ld: ../../vcpkg_installed/x64-linux/lib/libgdal.a(openjpegdataset.o): in function `JP2OpenJPEGDataset::ReadBlock(int, _IO_FILE*, int, int, void*, int, int*)':
openjpegdataset.cpp:(.text+0x7be): undefined reference to `opj_create_decompress'
/usr/bin/ld: openjpegdataset.cpp:(.text+0x7dd): undefined reference to `opj_set_info_handler'
...
/usr/bin/ld: ../../lib/libosgEarth.so.3.3.0: hidden symbol `opj_create_compress' isn't defined
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [src/osgEarth/CMakeFiles/osgEarth.dir/build.make:4918: lib/libosgEarth.so.3.3.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:1657: src/osgEarth/CMakeFiles/osgEarth.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

elbarto1980 avatar Aug 22 '22 16:08 elbarto1980

Give me a bit of time to reproduce and figure out what it is doing in Linux. This part: cmake -S osgearth-3.3 -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=~/OSG/osgearth-3.3 -DCMAKE_TOOLCHAIN_FILE=~/gitrepo/vcpkg/scripts/buildsystems/vcpkg.cmake -- Running vcpkg install -- Running vcpkg install - done

Where it is automagically finding and building all the dependencies is not something we have tested. Traditionally we split the two builds, let vcpkg build all the dependencies by using something like vcpkg install osgearth:x64-linux which places all the dependencies in the installed folder. Then clone and cmake osgearth with the buildscript to find all the dependencies from the vcpkg folder. This appears to be doing a manifest local install instead of referencing my pre-built vcpkg libraries and failing where I would bet if you try vcpkg install osgearth:x64-linux , it will succeed.

plevy avatar Aug 23 '22 04:08 plevy

OK, I get the same [ 53%] Linking CXX shared library ../../lib/libosgEarth.so /usr/bin/ld: ../../vcpkg_installed/x64-linux/lib/libgdal.a(openjpegdataset.o): in function JP2OpenJPEGDataset::ReadBlock(int, _IO_FILE*, int, int, void*, int, int*)': openjpegdataset.cpp:(.text+0x7be): undefined reference to opj_create_decompress'

plevy avatar Aug 23 '22 04:08 plevy

I tried various combinations to try to get this to work, but I think we decided the general issue is shared/dynamic vs static libraries. VCPKG by default builds and tests static and the dynamic is community supported and not tested. Building osgearth:x64-linux-dynamic did not work for me. Building all the dependencies static linking does work in vcpkg but then osgearth is really setup to build with dynamic linking. Even if I set shared libraries to OFF, it seemed to still build dynamic. I couldn't get both sides to build in the same linking style. Going back to what you were doing, you can remove the vcpkg.json file and that will stop the manifest build which is causing other problems as you noticed in gdal. If you clone vcpkg and vcpkg install osgearth:x64-linux, that will build all the dependencies and then you can reference the buildscript in the cmake build to find all the libraries. There is still an issue with resolving fontconfig (optional in openscenegraph) and then a couple more unresolved references trying to build the applications. You can dig deeper into it if you want to go down that path. The osgEarth source is patched to build in vcpkg, so there is some chance that applying the same changes would fix the problems but I did not try it.

The traditional linux build path is still easier using apt-get. It looks like this:

        sudo apt-get update -qq
        sudo apt-get install libgl-dev
        sudo apt-get install -y cmake
        sudo apt-get install -y libopenscenegraph-dev
        sudo apt-get install -y libgdal-dev
        sudo apt-get install -y libgeos-dev
        sudo apt-get install -y libsqlite3-dev
        sudo apt-get install -y protobuf-compiler libprotobuf-dev
        sudo apt-get install -y libpoco-dev

git clone --recurse-submodules https://github.com/gwaldron/osgearth.git osgearth
mkdir build

cd build
cmake ..
cmake --build . --parallel 4 --config Release

plevy avatar Aug 24 '22 15:08 plevy

Thank you @gwaldron, @plevy for your help.

In the meantime, I managed to rebuild from scratch (i.e. without vcpkg) the GL3-enabled version of both OSG 3.6.5 and OsgEarth 3.3.0 and I tested them within the software I am developing. It runs, but I will have a lot of work to do to upgrade my code as well and get rid of many warnings and other things that do not work as they should. I found out that I was leaning too much on the old GL fixed-function pipeline (FFP) mechanisms :sweat_smile: and, at the moment, I am not very proficient with modern OpenGL.

Basically, GL_LINE_STRIP geometries are not rendered at all ("Warning: Material::apply(State&) - not supported.") and the colors of imported models change when I move the camera (same warning: "Warning: Material::apply(State&) - not supported."). Appending ".osgearth_shadergen" in the osgDB::readNodeFile function removes the warnings but messes up the colors even more.

So, I think that, for now, I will keep both the GL2 and GL3 versions. I won't give up on GL3, but upgrading my code will take more time (and more study time) than I initially thought.

Thank you again! :+1:

elbarto1980 avatar Aug 24 '22 15:08 elbarto1980