Skip to content

Commit e44739e

Browse files
add resourceExists check to loadEmbeddedTexture before loading texture (#1542) (#1550)
(cherry picked from commit af656e3) Co-authored-by: John TGZ <[email protected]>
1 parent 78a2d03 commit e44739e

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

rviz_rendering/src/rviz_rendering/mesh_loader_helpers/assimp_loader.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -365,29 +365,33 @@ void AssimpLoader::setLightColorsFromAssimp(
365365
void AssimpLoader::loadEmbeddedTexture(
366366
const aiTexture * texture, const std::string & resource_path)
367367
{
368-
if (texture == nullptr) {
369-
RVIZ_RENDERING_LOG_ERROR_STREAM("null texture!");
370-
return;
371-
}
368+
// Check if the embedded texture already exists within TextureManager before proceeding to
369+
// load it.
370+
if (!Ogre::TextureManager::getSingleton().resourceExists(resource_path, ROS_PACKAGE_NAME)) {
371+
if (texture == nullptr) {
372+
RVIZ_RENDERING_LOG_ERROR_STREAM("null texture!");
373+
return;
374+
}
372375

373-
// use the format hint to try to load the image
374-
std::string format_hint(
375-
texture->achFormatHint,
376-
strnlen(texture->achFormatHint, sizeof(texture->achFormatHint)));
376+
// use the format hint to try to load the image
377+
std::string format_hint(
378+
texture->achFormatHint,
379+
strnlen(texture->achFormatHint, sizeof(texture->achFormatHint)));
377380

378-
Ogre::DataStreamPtr stream(
379-
new Ogre::MemoryDataStream(
380-
(unsigned char *)texture->pcData, texture->mWidth));
381+
Ogre::DataStreamPtr stream(
382+
new Ogre::MemoryDataStream(
383+
(unsigned char *)texture->pcData, texture->mWidth));
381384

382-
try {
383-
Ogre::Image image;
384-
image.load(stream, format_hint.c_str());
385-
Ogre::TextureManager::getSingleton().loadImage(
386-
resource_path, ROS_PACKAGE_NAME, image);
387-
} catch (Ogre::Exception & e) {
388-
RVIZ_RENDERING_LOG_ERROR_STREAM(
389-
"Could not load texture [" << resource_path.c_str() <<
390-
"] with format hint [" << format_hint << "]: " << e.what());
385+
try {
386+
Ogre::Image image;
387+
image.load(stream, format_hint.c_str());
388+
Ogre::TextureManager::getSingleton().loadImage(
389+
resource_path, ROS_PACKAGE_NAME, image);
390+
} catch (Ogre::Exception & e) {
391+
RVIZ_RENDERING_LOG_ERROR_STREAM(
392+
"Could not load texture [" << resource_path.c_str() <<
393+
"] with format hint [" << format_hint << "]: " << e.what());
394+
}
391395
}
392396
}
393397

0 commit comments

Comments
 (0)