Improved warning messages: most warnings about textures not

found will now be prefixed with a line indicating what kart
or track it comes from. Fixed crash in referee when a texture
did not exist. Irrlicht's warnings about missing textures
while loading a mesh will be prefixed by a line about which
kart/track is missing as well.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14491 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2013-11-20 10:56:42 +00:00
parent 1c78060772
commit e6660d7c74
8 changed files with 136 additions and 44 deletions

View File

@ -1069,6 +1069,29 @@ void IrrDriver::removeCameraSceneNode(scene::ICameraSceneNode *camera)
camera->remove();
} // removeCameraSceneNode
// ----------------------------------------------------------------------------
/** Sets an error message to be displayed when a texture is not found. This
* error message is shown before the "Texture '%s' not found" message. It can
* be used to supply additional details like what kart is currently being
* loaded.
* \param error Error message, potentially with a '%' which will be replaced
* with detail.
* \param detail String to replace a '%' in the error message.
*/
void IrrDriver::setTextureErrorMessage(const std::string &error,
const std::string &detail)
{
m_texture_error_message = StringUtils::insertValues(error, detail);
} // setTextureErrorMessage
// ----------------------------------------------------------------------------
/** Disables the texture error message again.
*/
void IrrDriver::unsetTextureErrorMessage()
{
m_texture_error_message = "";
} // unsetTextureErrorMessage
// ----------------------------------------------------------------------------
/** Loads a texture from a file and returns the texture object.
* \param filename File name of the texture to load.
@ -1150,9 +1173,11 @@ video::ITexture *IrrDriver::getTexture(const std::string &filename,
if (complain_if_not_found && out == NULL)
{
Log::error("irr_driver", "Texture '%s' not found; Put a breakpoint "
"at line %s:%i to debug!\n",
filename.c_str(), __FILE__, __LINE__);
if(m_texture_error_message.size()>0)
{
Log::error("irr_driver", m_texture_error_message.c_str());
}
Log::error("irr_driver", "Texture '%s' not found.", filename.c_str());
}
return out;

View File

@ -75,6 +75,10 @@ private:
/** Post-processing. */
PostProcessing *m_post_processing;
/** Additional details to be shown in case that a texture is not found.
* This is used to specify details like: "while loading kart '...'" */
std::string m_texture_error_message;
/** Flag to indicate if a resolution change is pending (which will be
* acted upon in the next update). None means no change, yes means
* change to new resolution and trigger confirmation dialog.
@ -193,6 +197,9 @@ public:
void printRenderStats();
bool supportsSplatting();
void requestScreenshot();
void setTextureErrorMessage(const std::string &error,
const std::string &detail="");
void unsetTextureErrorMessage();
void draw2dTriangle(const core::vector2df &a, const core::vector2df &b,
const core::vector2df &c,
@ -203,6 +210,35 @@ public:
// ------------------------------------------------------------------------
/** Convenience function that loads a texture with default parameters
* but includes an error message.
* \param filename File name of the texture to load.
* \param error Error message, potentially with a '%' which will be replaced
* with detail.
* \param detail String to replace a '%' in the error message.
*/
video::ITexture* getTexture(const std::string &filename,
const std::string &error_message,
const std::string &detail="")
{
setTextureErrorMessage(error_message, detail);
video::ITexture *tex = getTexture(filename);
unsetTextureErrorMessage();
return tex;
} // getTexture
// ------------------------------------------------------------------------
/** Returns the currently defined texture error message, which is used
* by event_handler.cpp to print additional info about irrlicht
* internal errors or warnings. If no error message is currently
* defined, the error message is "".
*/
const std::string &getTextureErrorMessage()
{
return m_texture_error_message;
} // getTextureErrorMessage
// ------------------------------------------------------------------------
/** Returns a list of all video modes supports by the graphics card. */
const std::vector<VideoMode>& getVideoModes() const { return m_modes; }

View File

@ -430,8 +430,9 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
else if (s=="" || s=="none")
m_adjust_image = ADJ_NONE;
else
printf("Incorrect adjust-image specification: '%s' - ignored.\n",
s.c_str());
Log::warn("material",
"Incorrect adjust-image specification: '%s' - ignored.",
s.c_str());
node->get("alpha", &m_alpha_blending );
node->get("light", &m_lighting );
@ -464,7 +465,8 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
}
else if (creaction.size() > 0)
{
fprintf(stderr, "[Material] WARNING: Unknown collision reaction '%s'\n", creaction.c_str());
Log::warn("Material","Unknown collision reaction '%s'",
creaction.c_str());
}
node->get("below-surface", &m_below_surface );
@ -573,9 +575,9 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
}
else if (s != "")
{
fprintf(stderr,
"Invalid graphical effect specification: '%s' - ignored.\n",
s.c_str());
Log::warn("material",
"Invalid graphical effect specification: '%s' - ignored.",
s.c_str());
}
else
{
@ -595,7 +597,8 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
}
else
{
fprintf(stderr, "[Material] WARNING: could not find normal map image in materials.xml\n");
Log::warn("material",
"Could not find normal map image in materials.xml");
}
node->get("normal-light-map", &m_normal_map_shader_lightmap);
@ -618,9 +621,8 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
else if (s == "additive") m_add = true;
else if (s == "coverage") m_alpha_to_coverage = true;
else if (s != "none")
fprintf(stderr,
"[Material] WARNING: Unknown compositing mode '%s'\n",
s.c_str());
Log::warn("material", "Unknown compositing mode '%s'",
s.c_str());
}
@ -665,10 +667,9 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
}
else
{
fprintf(stderr,
"[Material] WARNING: unknown node type '%s' for texture "
"'%s' - ignored.\n",
child_node->getName().c_str(), m_texname.c_str());
Log::warn("material", "Unknown node type '%s' for texture "
"'%s' - ignored.",
child_node->getName().c_str(), m_texname.c_str());
}
} // for i <node->getNumNodes()
@ -756,14 +757,16 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
if (complain_if_not_found && full_path.size() == 0)
{
fprintf(stderr, "[Material] WARNING, cannot find texture '%s'\n", m_texname.c_str());
Log::error("material", "Cannot find texture '%s'.", m_texname.c_str());
m_texture = NULL;
}
else
{
m_texture = irr_driver->getTexture(full_path,
isPreMul(),
isPreDiv(),
complain_if_not_found);
}
m_texture = irr_driver->getTexture(full_path,
isPreMul(),
isPreDiv(),
complain_if_not_found);
if (m_texture == NULL) return;
@ -780,8 +783,8 @@ void Material::install(bool is_full_path, bool complain_if_not_found)
}
else
{
fprintf(stderr, "Applying mask failed for '%s'!\n",
m_texname.c_str());
Log::warn("material", "Applying mask failed for '%s'!",
m_texname.c_str());
}
}
m_texture->grab();
@ -833,8 +836,8 @@ void Material::initCustomSFX(const XMLNode *sfx)
if (filename.empty())
{
fprintf(stderr, "[Material] WARNING: sfx node has no 'filename' "
"attribute, sound effect will be ignored\n");
Log::warn("material", "Sfx node has no 'filename' "
"attribute, sound effect will be ignored.");
return;
}
@ -912,10 +915,10 @@ void Material::initParticlesEffect(const XMLNode *node)
if (count == 0)
{
fprintf(stderr, "[Material::initParticlesEffect] WARNING: Particles "
"'%s' for material '%s' are declared but not used "
"(no emission condition set)\n",
base.c_str(), m_texname.c_str());
Log::warn("material", "initParticlesEffect: Particles "
"'%s' for material '%s' are declared but not used "
"(no emission condition set).",
base.c_str(), m_texname.c_str());
}
for (int c=0; c<count; c++)
@ -930,8 +933,8 @@ void Material::initParticlesEffect(const XMLNode *node)
}
else
{
fprintf(stderr, "[Material::initParticlesEffect] WARNING: Unknown "
"condition '%s' for material '%s'\n",
Log::warn("material", "initParticlesEffect: Unknown "
"condition '%s' for material '%s'",
conditions[c].c_str(), m_texname.c_str());
}
}
@ -985,9 +988,12 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
// materials.xml, if you want to set flags for all surfaces, see
// 'MaterialManager::setAllMaterialFlags'
if (m_deprecated || (m->getTexture(0) != NULL && ((core::stringc)m->getTexture(0)->getName()).find("deprecated") != -1))
if (m_deprecated ||
(m->getTexture(0) != NULL &&
((core::stringc)m->getTexture(0)->getName()).find("deprecated") != -1))
{
fprintf(stderr, "WARNING: track uses deprecated texture <%s>\n", m_texname.c_str());
Log::warn("material", "Track uses deprecated texture '%s'\n",
m_texname.c_str());
}

View File

@ -124,6 +124,8 @@ void Referee::init()
scene::IMeshBuffer *mb = m_st_referee_mesh->getMeshBuffer(i);
video::SMaterial &irrMaterial = mb->getMaterial();
video::ITexture* t=irrMaterial.getTexture(0);
if(!t) continue;
std::string name=StringUtils::getBasename(t->getName()
.getInternalName().c_str());
if(name==colors[0] || name==colors[1] ||name==colors[2] )

View File

@ -22,6 +22,7 @@
#include <IGUIEnvironment.h>
#include <IGUIListBox.h>
#include "graphics/irr_driver.hpp"
#include "guiengine/abstract_state_manager.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/modaldialog.hpp"
@ -192,14 +193,18 @@ bool EventHandler::OnEvent (const SEvent &event)
#else
return true; // EVENT_BLOCK
#endif
const std::string &error_info = irr_driver->getTextureErrorMessage();
if (event.LogEvent.Level == irr::ELL_WARNING)
{
printf("[Irrlicht Warning] %s\n", event.LogEvent.Text);
if(error_info.size()>0)
Log::warn("EventHandler", error_info.c_str());
Log::warn("Irrlicht", event.LogEvent.Text);
}
else if (event.LogEvent.Level == irr::ELL_ERROR)
{
printf("[Irrlicht Error] %s\n", event.LogEvent.Text);
if(error_info.size()>0)
Log::error("EventHandler", error_info.c_str());
Log::error("Irrlicht", event.LogEvent.Text);
}
}
return true;

View File

@ -217,6 +217,9 @@ void KartProperties::load(const std::string &filename, const std::string &node)
file_manager->pushModelSearchPath (m_root);
file_manager->pushTextureSearchPath(m_root);
irr_driver->setTextureErrorMessage("Error while loading kart '%s':",
m_name);
// addShared makes sure that these textures/material infos stay in memory
material_manager->addSharedMaterial(materials_file);
@ -269,6 +272,8 @@ void KartProperties::load(const std::string &filename, const std::string &node)
}
m_shadow_texture = irr_driver->getTexture(m_shadow_file);
irr_driver->unsetTextureErrorMessage();
file_manager->popTextureSearchPath();
file_manager->popModelSearchPath();

View File

@ -85,7 +85,10 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name, const
if (clickedTrack != NULL)
{
ITexture* screenshot = irr_driver->getTexture( clickedTrack->getScreenshotFile().c_str() );
ITexture* screenshot =
irr_driver->getTexture( clickedTrack->getScreenshotFile(),
"While loading screenshot for track '%s':",
clickedTrack->getFilename() );
new TrackInfoDialog(selection, clickedTrack->getIdent(),
translations->fribidize(clickedTrack->getName()),
@ -105,7 +108,10 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name, const
Track* clickedTrack = track_manager->getTrack(selection);
if (clickedTrack != NULL)
{
ITexture* screenshot = irr_driver->getTexture( clickedTrack->getScreenshotFile().c_str() );
ITexture* screenshot =
irr_driver->getTexture( clickedTrack->getScreenshotFile(),
"While loading screenshot for track '%s'",
clickedTrack->getFilename());
new TrackInfoDialog(selection, clickedTrack->getIdent(),
translations->fribidize(clickedTrack->getName()),
@ -252,14 +258,16 @@ void TracksScreen::init()
buildTrackList();
// select something for the game master
// FIXME: 'setSelection' will not scroll up to the passed track, so if given track
// is not visible with current scrolling this fails
// select old track for the game master (if found)
irr_driver->setTextureErrorMessage(
"While loading screenshot in track screen for last track '%s':",
UserConfigParams::m_last_track);
if (!tracks_widget->setSelection(UserConfigParams::m_last_track,
PLAYER_ID_GAME_MASTER, true))
{
tracks_widget->setSelection(0, PLAYER_ID_GAME_MASTER, true);
}
irr_driver->unsetTextureErrorMessage();
}
// -----------------------------------------------------------------------------

View File

@ -1353,6 +1353,9 @@ void Track::createWater(const XMLNode &node)
*/
void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
{
// Use m_filename to also get the path, not only the identifier
irr_driver->setTextureErrorMessage("While loading track '%s'",
m_filename );
if(!m_reverse_available)
{
reverse_track = false;
@ -1777,6 +1780,8 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
std::string dir = StringUtils::getPath(m_filename);
easter_world->readData(dir+"/easter_eggs.xml");
}
irr_driver->unsetTextureErrorMessage();
} // loadTrackModel
//-----------------------------------------------------------------------------