<div dir="ltr"><div><div>Hi David,<br><br></div>A floating point exception is something you'll need to track down with a debugger as it's not something that usually could be tracked down with a code review.<br><br></div><div>One you have a stack trace and share this then perhaps others might be able to help. Other information that would help would be the platform you are using, OSG version. whether standard OSG examples like osgshadow work OK etc.<br></div><div><br></div>Robert.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 29 June 2015 at 12:42, david boublil <span dir="ltr"><<a href="mailto:davboub@gmail.com" target="_blank">davboub@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I am trying to run a simple code that I got from tutorial which is supposed to add shadows to the scene but I am getting a "floating point exception" error. I have no idea how I can solve it, I would really appreciated some help...<br>
<br>
Here is the source code:<br>
<br>
using namespace osg;<br>
int main()<br>
{<br>
<br>
//Declaration of the objects that will form our scene<br>
osgViewer::Viewer viewer;<br>
ref_ptr<Group> scene (new Group);<br>
ref_ptr<Geode> objectGeode (new Geode);<br>
ref_ptr<Geode> terrainGeode (new Geode);<br>
ref_ptr<Geode> lightMarkerGeode (new Geode);<br>
<br>
//Shadow stuff!!<br>
<br>
ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene;<br>
ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap;<br>
shadowedScene->setShadowTechnique(sm.get());<br>
//Main light source<br>
Vec3 lightPosition(0,0,3);<br>
LightSource* ls = new LightSource;<br>
ls->getLight()->setPosition(Vec4(lightPosition,1));<br>
ls->getLight()->setAmbient(Vec4(0.2,0.2,0.2,1.0));<br>
ls->getLight()->setDiffuse(Vec4(0.6,0.6,0.6,1.0));<br>
<br>
shadowedScene->addChild(scene.get());<br>
shadowedScene->addChild(ls);<br>
shadowedScene->addChild(lightMarkerGeode.get());<br>
<br>
//Next we define the material property of our objects<br>
// material<br>
ref_ptr<Material> matirial = new Material;<br>
matirial->setColorMode(Material::DIFFUSE);<br>
matirial->setAmbient(Material::FRONT_AND_BACK, Vec4(0, 0, 0, 1));<br>
matirial->setSpecular(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));<br>
matirial->setShininess(Material::FRONT_AND_BACK, 64);<br>
scene->getOrCreateStateSet()->setAttributeAndModes(matirial.get(), StateAttribute::ON);<br>
<br>
<br>
//Adding the terrain and object nodes to the root node<br>
scene->addChild(objectGeode.get());<br>
scene->addChild(terrainGeode.get());<br>
<br>
//The terrain first, a flatten box<br>
terrainGeode->addDrawable(new ShapeDrawable(new Box(Vec3f(),5,7,0.05f)));<br>
<br>
//Now we can define our world made of several objects<br>
//The capsule<br>
objectGeode->addDrawable(new ShapeDrawable(new Capsule(Vec3(1,-1,1),0.3f,0.5f)));<br>
<br>
//The box<br>
objectGeode->addDrawable(new ShapeDrawable(new Box(Vec3(-1,1,1),1,1,1)));<br>
<br>
//The sphere<br>
objectGeode->addDrawable(new ShapeDrawable(new Sphere(Vec3(1,2,1),0.5f)));<br>
//objectGeode->addDrawable(new ShapeDrawable(new Sphere(Vec3(0,0,4.5f),0.1f)));<br>
<br>
//And finally the light marker: a small sphere<br>
lightMarkerGeode->addDrawable(new ShapeDrawable(new Sphere(lightPosition+osg::Vec3(0,0,0.5f),0.1f)));<br>
viewer.setSceneData( shadowedScene.get() );<br>
<br>
//Stats Event Handler s key<br>
viewer.addEventHandler(new osgViewer::StatsHandler);<br>
<br>
// add the state manipulator<br>
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );<br>
<br>
//Windows size handler<br>
viewer.addEventHandler(new osgViewer::WindowSizeHandler);<br>
<br>
return(viewer .run());<br>
<br>
}<br>
<br>
I used the debug mode and got the following output:<br>
<br>
RegisterWindowingSystemInterfaceProxy()<br>
X11WindowingSystemInterface()<br>
GraphicsContext::setWindowingSystemInterface() 0x2030620 0x7fdb2a28a5f0<br>
CullSettings::readEnvironmentalVariables()<br>
DatabasePager::addDatabaseThread() HANDLE_NON_HTTP<br>
DatabasePager::addDatabaseThread() HANDLE_ONLY_HTTP<br>
CullSettings::readEnvironmentalVariables()<br>
CullSettings::readEnvironmentalVariables()<br>
CullSettings::readEnvironmentalVariables()<br>
CullSettings::readEnvironmentalVariables()<br>
CullSettings::readEnvironmentalVariables()<br>
itr='/opt/matlab/sys/openscenegraph/lib/glnxa64'<br>
FindFileInPath() : trying /opt/matlab/sys/openscenegraph/lib/glnxa64/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
itr='/opt/matlab/sys/os/glnxa64'<br>
FindFileInPath() : trying /opt/matlab/sys/os/glnxa64/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
itr='/opt/matlab/bin/glnxa64'<br>
FindFileInPath() : trying /opt/matlab/bin/glnxa64/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
itr='/opt/matlab/extern/lib/glnxa64'<br>
FindFileInPath() : trying /opt/matlab/extern/lib/glnxa64/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
itr='/opt/matlab/sys/java/jre/glnxa64/jre/lib/amd64/native_threads'<br>
FindFileInPath() : trying /opt/matlab/sys/java/jre/glnxa64/jre/lib/amd64/native_threads/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
itr='/opt/matlab/sys/java/jre/glnxa64/jre/lib/amd64/server'<br>
FindFileInPath() : trying /opt/matlab/sys/java/jre/glnxa64/jre/lib/amd64/server/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
itr='/homes/davidb/Downloads/local/Mesa-7.0.3/lib64/'<br>
FindFileInPath() : trying /homes/davidb/Downloads/local/Mesa-7.0.3/lib64/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
itr='/homes/davidb/Downloads/local/lib64/osgPlugins-2.8.1/'<br>
FindFileInPath() : trying /homes/davidb/Downloads/local/lib64/osgPlugins-2.8.1/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
itr='/homes/davidb/Downloads/local/lib64'<br>
FindFileInPath() : trying /homes/davidb/Downloads/local/lib64/osgPlugins-2.8.1/osgdb_jpeg.so ...<br>
FindFileInPath() : USING /homes/davidb/Downloads/local/lib64/osgPlugins-2.8.1/osgdb_jpeg.so<br>
Opened DynamicLibrary osgPlugins-2.8.1/osgdb_jpeg.so<br>
FindFileInPath(ground.jpg): returning ground.jpg<br>
<br>
try to read image<br>
can't read image with osgdb<br>
View::setSceneData() Reusing exisitng scene0x2031480<br>
CullSettings::readEnvironmentalVariables()<br>
CullSettings::readEnvironmentalVariables()<br>
CullSettings::readEnvironmentalVariables()<br>
CullSettings::readEnvironmentalVariables()<br>
CullSettings::readEnvironmentalVariables()<br>
Viewer::realize() - No valid contexts found, setting up view across all screens.<br>
GraphicsContext::getWindowingSystemInterface() 0x2030620 0x7fdb2a28a5f0<br>
GraphicsContext::registerGraphicsContext 0x204b140<br>
GraphicsContext::getWindowingSystemInterface() 0x2030620 0x7fdb2a28a5f0<br>
GraphicsContext::createNewContextID() creating contextID=0<br>
Updating the MaxNumberOfGraphicsContexts to 1<br>
GraphicsWindow has been created successfully.<br>
Viewer::startThreading() - starting threading<br>
Viewer::startThreading() - contexts.size()=1<br>
Making scene thread safe<br>
Doing add<br>
Doing add<br>
Doing add<br>
gc->getGraphicsThread()->startThread() 0x233c5e0<br>
Set up threading<br>
View::init()<br>
FocusOut/UnmapNotify event received<br>
FocusIn event received<br>
KeymapNotify event received<br>
CullSettings::readEnvironmentalVariables()<br>
Done DatabasePager::addLoadedDataToSceneGraph0.001ms, 0ms objects0<br>
<br>
Doing run 0x233c5e0 isRunning()=1<br>
OpenGL extensions supported by installed OpenGL drivers are:<br>
GL_APPLE_packed_pixels<br>
GL_APPLE_vertex_array_object<br>
GL_ARB_depth_texture<br>
GL_ARB_draw_buffers<br>
GL_ARB_fragment_program<br>
GL_ARB_fragment_shader<br>
GL_ARB_half_float_pixel<br>
GL_ARB_imaging<br>
GL_ARB_multisample<br>
GL_ARB_multitexture<br>
GL_ARB_occlusion_query<br>
GL_ARB_pixel_buffer_object<br>
GL_ARB_point_parameters<br>
GL_ARB_point_sprite<br>
GL_ARB_shader_objects<br>
GL_ARB_shading_language_100<br>
GL_ARB_shading_language_120<br>
GL_ARB_shadow<br>
GL_ARB_shadow_ambient<br>
GL_ARB_texture_border_clamp<br>
GL_ARB_texture_compression<br>
GL_ARB_texture_cube_map<br>
GL_ARB_texture_env_add<br>
GL_ARB_texture_env_combine<br>
GL_ARB_texture_env_crossbar<br>
GL_ARB_texture_env_dot3<br>
GL_ARB_texture_mirrored_repeat<br>
GL_ARB_texture_non_power_of_two<br>
GL_ARB_texture_rectangle<br>
GL_ARB_transpose_matrix<br>
GL_ARB_vertex_buffer_object<br>
GL_ARB_vertex_program<br>
GL_ARB_vertex_shader<br>
GL_ARB_window_pos<br>
GL_ATI_blend_equation_separate<br>
GL_ATI_fragment_shader<br>
GL_ATI_separate_stencil<br>
GL_ATI_texture_env_combine3<br>
GL_ATI_texture_mirror_once<br>
GL_EXT_abgr<br>
GL_EXT_bgra<br>
GL_EXT_blend_color<br>
GL_EXT_blend_equation_separate<br>
GL_EXT_blend_func_separate<br>
GL_EXT_blend_logic_op<br>
GL_EXT_blend_minmax<br>
GL_EXT_blend_subtract<br>
GL_EXT_clip_volume_hint<br>
GL_EXT_compiled_vertex_array<br>
GL_EXT_convolution<br>
GL_EXT_copy_texture<br>
GL_EXT_depth_bounds_test<br>
GL_EXT_draw_range_elements<br>
GL_EXT_fog_coord<br>
GL_EXT_framebuffer_blit<br>
GL_EXT_framebuffer_object<br>
GL_EXT_gpu_program_parameters<br>
GL_EXT_histogram<br>
GL_EXT_multi_draw_arrays<br>
GL_EXT_packed_depth_stencil<br>
GL_EXT_packed_pixels<br>
GL_EXT_paletted_texture<br>
GL_EXT_pixel_buffer_object<br>
GL_EXT_point_parameters<br>
GL_EXT_polygon_offset<br>
GL_EXT_rescale_normal<br>
GL_EXT_secondary_color<br>
GL_EXT_separate_specular_color<br>
GL_EXT_shadow_funcs<br>
GL_EXT_shared_texture_palette<br>
GL_EXT_stencil_wrap<br>
GL_EXT_subtexture<br>
GL_EXT_texture<br>
GL_EXT_texture3D<br>
GL_EXT_texture_edge_clamp<br>
GL_EXT_texture_env_add<br>
GL_EXT_texture_env_combine<br>
GL_EXT_texture_env_dot3<br>
GL_EXT_texture_lod_bias<br>
GL_EXT_texture_mirror_clamp<br>
GL_EXT_texture_object<br>
GL_EXT_texture_rectangle<br>
GL_EXT_texture_sRGB<br>
GL_EXT_timer_query<br>
GL_EXT_vertex_array<br>
GL_IBM_multimode_draw_arrays<br>
GL_IBM_rasterpos_clip<br>
GL_IBM_texture_mirrored_repeat<br>
GL_INGR_blend_func_separate<br>
GL_MESA_pack_invert<br>
GL_MESA_program_debug<br>
GL_MESA_resize_buffers<br>
GL_MESA_window_pos<br>
GL_MESA_ycbcr_texture<br>
GL_NV_blend_square<br>
GL_NV_fragment_program<br>
GL_NV_light_max_exponent<br>
GL_NV_point_sprite<br>
GL_NV_texgen_reflection<br>
GL_NV_texture_rectangle<br>
GL_NV_vertex_program<br>
GL_NV_vertex_program1_1<br>
GL_OES_read_format<br>
GL_SGIS_generate_mipmap<br>
GL_SGIS_texture_border_clamp<br>
GL_SGIS_texture_edge_clamp<br>
GL_SGIS_texture_lod<br>
GL_SGIX_depth_texture<br>
GL_SGIX_shadow<br>
GL_SGIX_shadow_ambient<br>
GL_SGI_color_matrix<br>
GL_SGI_color_table<br>
GL_SGI_texture_color_table<br>
GL_SUN_multi_draw_arrays<br>
OpenGL extension 'GL_ARB_vertex_program' is supported.<br>
OpenGL extension 'GL_EXT_secondary_color' is supported.<br>
OpenGL extension 'GL_EXT_fog_coord' is supported.<br>
OpenGL extension 'GL_ARB_multitexture' is supported.<br>
OpenGL extension 'GL_NV_occlusion_query' is not supported.<br>
OpenGL extension 'GL_ARB_occlusion_query' is supported.<br>
OpenGL extension 'GL_EXT_timer_query' is supported.<br>
OpenGL extension '' is not supported.<br>
Done DatabasePager::addLoadedDataToSceneGraph0ms, 0.001ms objects0<br>
<br>
OpenGL extension 'GL_ARB_pixel_buffer_object' is supported.<br>
OpenGL extension 'GL_ARB_fragment_program' is supported.<br>
OpenGL extension 'GL_EXT_framebuffer_object' is supported.<br>
OpenGL extension 'GL_EXT_framebuffer_blit' is supported.<br>
OpenGL extension 'GL_EXT_framebuffer_multisample' is not supported.<br>
OpenGL extension 'GL_NV_framebuffer_multisample_coverage' is not supported.<br>
OpenGL extension 'GL_EXT_packed_depth_stencil' is supported.<br>
OpenGL extension 'GL_ARB_shader_objects' is supported.<br>
OpenGL extension 'GL_ARB_vertex_shader' is supported.<br>
OpenGL extension 'GL_ARB_fragment_shader' is supported.<br>
OpenGL extension 'GL_ARB_shading_language_100' is supported.<br>
OpenGL extension 'GL_EXT_geometry_shader4' is not supported.<br>
OpenGL extension 'GL_EXT_gpu_shader4' is not supported.<br>
glVersion=2.1, isGlslSupported=YES, glslLanguageVersion=1.1<br>
OpenGL extension 'GL_ARB_vertex_program' is supported.<br>
Setting up osg::Camera::FRAME_BUFFER_OBJECT<br>
OpenGL extension 'GL_ARB_multitexture' is supported.<br>
OpenGL extension 'GL_EXT_texture_filter_anisotropic' is not supported.<br>
OpenGL extension 'GL_ARB_texture_compression' is supported.<br>
OpenGL extension 'GL_EXT_texture_compression_s3tc' is not supported.<br>
OpenGL extension 'GL_IBM_texture_mirrored_repeat' is supported.<br>
OpenGL extension 'GL_EXT_texture_edge_clamp' is supported.<br>
OpenGL extension 'GL_ARB_texture_border_clamp' is supported.<br>
OpenGL extension 'GL_SGIS_generate_mipmap' is supported.<br>
OpenGL extension 'GL_ARB_shadow' is supported.<br>
OpenGL extension 'GL_ARB_shadow_ambient' is supported.<br>
OpenGL extension 'GL_APPLE_client_storage' is not supported.<br>
OpenGL extension 'GL_ARB_texture_non_power_of_two' is supported.<br>
OpenGL extension 'GL_EXT_texture_integer' is not supported.<br>
Setting up osg::Camera::FRAME_BUFFER<br>
<br>
Compiling FRAGMENT source:<br>
uniform sampler2D osgShadow_baseTexture;<br>
uniform sampler2DShadow osgShadow_shadowTexture;<br>
uniform vec2 osgShadow_ambientBias;<br>
<br>
void main(void)<br>
{<br>
vec4 color = gl_Color * texture2D( osgShadow_baseTexture, gl_TexCoord[0].xy );<br>
gl_FragColor = color * (osgShadow_ambientBias.x + shadow2DProj( osgShadow_shadowTexture, gl_TexCoord[1] ) * osgShadow_ambientBias.y);<br>
}<br>
<br>
Linking osg::Program "" id=1 contextID=0<br>
Floating point exception<br>
./a.out: Floating point exception<br>
<br>
Thank a lot!<br>
<br>
Cheers,<br>
David<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=64208#64208" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=64208#64208</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br></div>