more null checks in places where we're calling createAppearance; some cleanup

This commit is contained in:
DarthArgus
2016-01-07 22:05:32 -06:00
parent 1ad5f8d882
commit 1d67bdd186
7 changed files with 95 additions and 51 deletions
@@ -232,14 +232,21 @@ const AppearanceTemplate *AppearanceTemplateList::fetch(const char *const fileNa
DEBUG_WARNING(true, ("AppearanceTemplateList::fetch could not open '%s', using default", fileName));
actualFileName = getDefaultAppearanceTemplateName();
}
else
if (actualFileName)
{
found = true;
//-- search for the appearance
AppearanceTemplate *const appearanceTemplate = create(actualFileName);
//-- search for the appearance
AppearanceTemplate *const appearanceTemplate = create(actualFileName);
//-- up the reference count
return fetch(appearanceTemplate);
//-- up the reference count
return fetch(appearanceTemplate);
}
DEBUG_WARNING(true, ("AppearanceTemplateList::fetch actualFileName fetch for %s failed.", actualFileName));
return NULL;
}
// ----------------------------------------------------------------------
@@ -389,18 +396,18 @@ Appearance *AppearanceTemplateList::createAppearance(const char *const fileName)
{
DEBUG_FATAL(!ms_installed, ("not installed"));
#ifdef _DEBUG
DataLint::pushAsset(fileName);
#endif
//-- get the appearance template
const AppearanceTemplate *const appearanceTemplate = fetch(fileName);
if(!appearanceTemplate){
if (appearanceTemplate == NULL){
DEBUG_WARNING(true, ("FIX ME: Appearance template for %s could not be fetched - is it missing?", fileName));
return NULL; // Cekis: TODO: Figure out why the template can't be fetched.
}
#ifdef _DEBUG
DataLint::pushAsset(fileName);
#endif
//-- creating the appearance will increment the reference count
Appearance *const appearance = appearanceTemplate->createAppearance();
@@ -585,8 +592,9 @@ AppearanceTemplate *AppearanceTemplateListNamespace::create(const char *const fi
const Tag tag = iff.getCurrentName();
TagBindingMap::iterator iter = ms_tagBindingMap.find(tag);
if (iter != ms_tagBindingMap.end())
if (iter != ms_tagBindingMap.end()) {
appearanceTemplate = iter->second(actualFileName.getString(), &iff);
}
else
{
char tagString[5];
@@ -2460,8 +2460,11 @@ void Object::setAppearanceByName(char const *path)
// Create the object's new appearance
Appearance *appearance = AppearanceTemplateList::createAppearance(path);
setAppearance(appearance);
if (appearance != NULL)
{
setAppearance(appearance);
}
}
else
{
@@ -3270,6 +3273,10 @@ void Object::setAlternateAppearance(const char * path)
if (TreeFile::exists(path))
{
alternateAppearance = AppearanceTemplateList::createAppearance(path);
if (alternateAppearance == NULL) {
return;
}
}
else
{
@@ -431,11 +431,14 @@ void CellProperty::initialize(const PortalProperty &portalProperty, int cellInde
m_appearanceObject->setDebugName("Cell appearance object");
m_appearanceObject->attachToObject_p(&getOwner(), true);
Appearance * const appearance = AppearanceTemplateList::createAppearance(cellTemplate.getAppearanceName());
appearance->setShadowBlobAllowed();
m_appearanceObject->setAppearance(appearance);
if (ms_addToRenderWorldHook)
ms_addToRenderWorldHook(*m_appearanceObject);
if (appearance != NULL) {
appearance->setShadowBlobAllowed();
m_appearanceObject->setAppearance(appearance);
if (ms_addToRenderWorldHook)
ms_addToRenderWorldHook(*m_appearanceObject);
}
}
// ----------
@@ -460,8 +460,10 @@ void PortalProperty::debugPrint(std::string &buffer) const
void PortalProperty::createAppearance()
{
Appearance * const appearance = AppearanceTemplateList::createAppearance(m_template->getExteriorAppearanceName());
appearance->setShadowBlobAllowed();
getOwner().setAppearance(appearance);
if (appearance != NULL) {
appearance->setShadowBlobAllowed();
getOwner().setAppearance(appearance);
}
}
// ----------------------------------------------------------------------