Skip to content

Commit

Permalink
Debug|World: Avoid crash when analyzing alpha of a missing sprite tex…
Browse files Browse the repository at this point in the history
…ture

IssueID #1964
  • Loading branch information
skyjake committed Feb 23, 2015
1 parent ba14456 commit 04452f9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions doomsday/client/src/world/p_mobj.cpp
Expand Up @@ -568,19 +568,22 @@ float Mobj_ShadowStrength(mobj_t *mo)

TextureVariant const *texture = matAnimator.texUnit(MaterialAnimator::TU_LAYER0).texture;
DENG2_ASSERT(texture);
auto const *aa = (averagealpha_analysis_t const *)texture->base().analysisDataPointer(Texture::AverageAlphaAnalysis);
DENG2_ASSERT(aa);
if(texture)
{
auto const *aa = (averagealpha_analysis_t const *)texture->base().analysisDataPointer(Texture::AverageAlphaAnalysis);
DENG2_ASSERT(aa);

// We use an average which factors in the coverage ratio
// of alpha:non-alpha pixels.
/// @todo Constant weights could stand some tweaking...
float weightedSpriteAlpha = aa->alpha * (0.4f + (1 - aa->coverage) * 0.6f);
// We use an average which factors in the coverage ratio
// of alpha:non-alpha pixels.
/// @todo Constant weights could stand some tweaking...
float weightedSpriteAlpha = aa->alpha * (0.4f + (1 - aa->coverage) * 0.6f);

// Almost entirely translucent sprite? => no shadow.
if(weightedSpriteAlpha < minSpriteAlphaLimit) return 0;
// Almost entirely translucent sprite? => no shadow.
if(weightedSpriteAlpha < minSpriteAlphaLimit) return 0;

// Apply this factor.
strength *= de::min(1.f, .2f + weightedSpriteAlpha);
// Apply this factor.
strength *= de::min(1.f, .2f + weightedSpriteAlpha);
}
}
}
}
Expand Down

0 comments on commit 04452f9

Please sign in to comment.