From b8906def866237d927a5ffffd1a19262b47cc42f Mon Sep 17 00:00:00 2001 From: epernod Date: Thu, 9 Apr 2026 01:51:50 +0200 Subject: [PATCH 1/2] [Visual] Fix crash when texturename is not leading to a valid texture file --- .../src/sofa/component/visual/VisualModelImpl.cpp | 10 +++++++--- .../src/sofa/gl/component/rendering3d/OglModel.cpp | 7 +++---- .../src/sofa/gl/component/rendering3d/OglModel.h | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp b/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp index 5698776ff6c..7b2979e5763 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp @@ -130,7 +130,7 @@ VisualModelImpl::VisualModelImpl() //const std::string &name, std::string filena , d_vertPosIdx (initData (&d_vertPosIdx, "vertPosIdx", "If vertices have multiple normals/texcoords stores vertices position indices")) , d_vertNormIdx (initData (&d_vertNormIdx, "vertNormIdx", "If vertices have multiple normals/texcoords stores vertices normal indices")) , d_fileMesh (initData (&d_fileMesh, "filename", " Path to an ogl model")) - , d_texturename (initData (&d_texturename, "texturename", "Name of the Texture")) + , d_texturename (initData (&d_texturename, "texturename", "Full path of the texture file")) , d_translation (initData (&d_translation, Vec3Real(), "translation", "Initial Translation of the object")) , d_rotation (initData (&d_rotation, Vec3Real(), "rotation", "Initial Rotation of the object")) , d_scale (initData (&d_scale, Vec3Real(1.0, 1.0, 1.0), "scale3d", "Initial Scale of the object")) @@ -224,7 +224,11 @@ void VisualModelImpl::doDrawVisual(const core::visual::VisualParams* vparams) if (m_textureChanged) { deleteTextures(); - loadTexture(d_texturename.getFullPath()); + std::string textureFilename = d_texturename.getFullPath(); + if (sofa::helper::system::DataRepository.findFile(textureFilename)) + { + loadTexture(d_texturename.getFullPath()); + } m_textureChanged = false; } initVisual(vparams); @@ -491,7 +495,7 @@ bool VisualModelImpl::load(const std::string& filename, const std::string& loade const bool textureLoaded = loadTexture(textureName); if(!textureLoaded) { - msg_error()<<"Texture "<(img, true, true, false, d_srgbTexturing.getValue()); return true; } diff --git a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglModel.h b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglModel.h index e9d8ba8ded8..f06189087d6 100644 --- a/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglModel.h +++ b/Sofa/GL/Component/Rendering3D/src/sofa/gl/component/rendering3d/OglModel.h @@ -71,7 +71,7 @@ class SOFA_GL_COMPONENT_RENDERING3D_API OglModel : public sofa::component::visua Data destFactor; ///< if alpha blending is enabled this specifies how the red, green, blue, and alpha destination blending factors are computed GLenum blendEq, sfactor, dfactor; - sofa::gl::Texture *m_tex; //this texture is used only if a texture name is specified in the scn + std::unique_ptr m_tex; //this texture is used only if a texture name is specified in the scn GLuint vbo, iboEdges, iboTriangles, iboQuads; bool VBOGenDone, initDone, useEdges, useTriangles, useQuads, canUsePatches; size_t oldVerticesSize, oldNormalsSize, oldTexCoordsSize, oldTangentsSize, oldBitangentsSize, oldEdgesSize, oldTrianglesSize, oldQuadsSize; @@ -123,7 +123,7 @@ class SOFA_GL_COMPONENT_RENDERING3D_API OglModel : public sofa::component::visua bool isUseTriangles() { return useTriangles; } bool isUseQuads() { return useQuads; } - sofa::gl::Texture* getTex() const { return m_tex; } + sofa::gl::Texture* getTex() const { return m_tex.get(); } GLuint getVbo() { return vbo; } GLuint getIboEdges() { return iboEdges; } GLuint getIboTriangles() { return iboTriangles; } From f7f796b87614e61cb3cd0bb70d8c211703492c11 Mon Sep 17 00:00:00 2001 From: erik pernod Date: Thu, 9 Apr 2026 10:52:34 +0200 Subject: [PATCH 2/2] Update Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp --- .../Visual/src/sofa/component/visual/VisualModelImpl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp b/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp index 7b2979e5763..bcbecf7ab9f 100644 --- a/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp +++ b/Sofa/Component/Visual/src/sofa/component/visual/VisualModelImpl.cpp @@ -229,6 +229,10 @@ void VisualModelImpl::doDrawVisual(const core::visual::VisualParams* vparams) { loadTexture(d_texturename.getFullPath()); } + else + { + msg_error() << "Texture " << textureFilename << " cannot be loaded"; + } m_textureChanged = false; } initVisual(vparams);