Skip to content

Commit af656e3

Browse files
authored
add resourceExists check to loadEmbeddedTexture before loading texture (#1542)
* add resourceExists check to loadEmbeddedTexture before loading texture * added comments * update comments
1 parent a3607ea commit af656e3

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
@@ -375,29 +375,33 @@ void AssimpLoader::setLightColorsFromAssimp(
375375
void AssimpLoader::loadEmbeddedTexture(
376376
const aiTexture * texture, const std::string & resource_path)
377377
{
378-
if (texture == nullptr) {
379-
RVIZ_RENDERING_LOG_ERROR_STREAM("null texture!");
380-
return;
381-
}
378+
// Check if the embedded texture already exists within TextureManager before proceeding to
379+
// load it.
380+
if (!Ogre::TextureManager::getSingleton().resourceExists(resource_path, ROS_PACKAGE_NAME)) {
381+
if (texture == nullptr) {
382+
RVIZ_RENDERING_LOG_ERROR_STREAM("null texture!");
383+
return;
384+
}
382385

383-
// use the format hint to try to load the image
384-
std::string format_hint(
385-
texture->achFormatHint,
386-
strnlen(texture->achFormatHint, sizeof(texture->achFormatHint)));
386+
// use the format hint to try to load the image
387+
std::string format_hint(
388+
texture->achFormatHint,
389+
strnlen(texture->achFormatHint, sizeof(texture->achFormatHint)));
387390

388-
Ogre::DataStreamPtr stream(
389-
new Ogre::MemoryDataStream(
390-
(unsigned char *)texture->pcData, texture->mWidth));
391+
Ogre::DataStreamPtr stream(
392+
new Ogre::MemoryDataStream(
393+
(unsigned char *)texture->pcData, texture->mWidth));
391394

392-
try {
393-
Ogre::Image image;
394-
image.load(stream, format_hint.c_str());
395-
Ogre::TextureManager::getSingleton().loadImage(
396-
resource_path, ROS_PACKAGE_NAME, image);
397-
} catch (Ogre::Exception & e) {
398-
RVIZ_RENDERING_LOG_ERROR_STREAM(
399-
"Could not load texture [" << resource_path.c_str() <<
400-
"] with format hint [" << format_hint << "]: " << e.what());
395+
try {
396+
Ogre::Image image;
397+
image.load(stream, format_hint.c_str());
398+
Ogre::TextureManager::getSingleton().loadImage(
399+
resource_path, ROS_PACKAGE_NAME, image);
400+
} catch (Ogre::Exception & e) {
401+
RVIZ_RENDERING_LOG_ERROR_STREAM(
402+
"Could not load texture [" << resource_path.c_str() <<
403+
"] with format hint [" << format_hint << "]: " << e.what());
404+
}
401405
}
402406
}
403407

0 commit comments

Comments
 (0)