From 619a721a30731d1ff599873d37b20ee05ad81cf9 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Wed, 3 Dec 2014 16:47:37 -0600 Subject: Improve resource error logging Actually display the name of the item or the filename of the item that we were unable to load in the log to make it easier to determine what went wrong. Change-Id: I027b35aab286e4d0f1957bcfb28ed40d81f9bbb2 --- gui/resources.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'gui') diff --git a/gui/resources.cpp b/gui/resources.cpp index 5f3923d10..74f020b62 100644 --- a/gui/resources.cpp +++ b/gui/resources.cpp @@ -149,8 +149,10 @@ ImageResource::ImageResource(xml_node<>* node, ZipArchive* pZip) std::string file; mSurface = NULL; - if (!node) + if (!node) { + LOGERR("ImageResource node is NULL\n"); return; + } if (node->first_attribute("filename")) file = node->first_attribute("filename")->value(); @@ -261,10 +263,13 @@ void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip) FontResource* res = new FontResource(child, pZip); if (res == NULL || res->GetResource() == NULL) { - xml_attribute<>* attr_name = child->first_attribute("name"); + std::string res_name; + if (child->first_attribute("name")) + res_name = child->first_attribute("name")->value(); + if (res_name.empty() && child->first_attribute("filename")) + res_name = child->first_attribute("filename")->value(); - if (!attr_name) { - std::string res_name = attr_name->value(); + if (!res_name.empty()) { LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str()); } else LOGERR("Resource type (%s) failed to load\n", type.c_str()); @@ -281,10 +286,13 @@ void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip) ImageResource* res = new ImageResource(child, pZip); if (res == NULL || res->GetResource() == NULL) { - xml_attribute<>* attr_name = child->first_attribute("name"); + std::string res_name; + if (child->first_attribute("name")) + res_name = child->first_attribute("name")->value(); + if (res_name.empty() && child->first_attribute("filename")) + res_name = child->first_attribute("filename")->value(); - if (!attr_name) { - std::string res_name = attr_name->value(); + if (!res_name.empty()) { LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str()); } else LOGERR("Resource type (%s) failed to load\n", type.c_str()); @@ -301,10 +309,13 @@ void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip) AnimationResource* res = new AnimationResource(child, pZip); if (res == NULL || res->GetResource() == NULL) { - xml_attribute<>* attr_name = child->first_attribute("name"); + std::string res_name; + if (child->first_attribute("name")) + res_name = child->first_attribute("name")->value(); + if (res_name.empty() && child->first_attribute("filename")) + res_name = child->first_attribute("filename")->value(); - if (!attr_name) { - std::string res_name = attr_name->value(); + if (!res_name.empty()) { LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str()); } else LOGERR("Resource type (%s) failed to load\n", type.c_str()); -- cgit v1.2.3