mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-06 17:41:04 +00:00
ParticleSpawner: Fix crash caused by empty texture
no_texture.png is now used as a fallback (if available), like already seen with registered items with empty 'inventory_image'.
This commit is contained in:
parent
c9230c5c09
commit
d60f909566
2 changed files with 14 additions and 3 deletions
|
@ -31,6 +31,10 @@ ClientParticleTexture::ClientParticleTexture(const ServerParticleTexture& p, ITe
|
|||
tex = p;
|
||||
// note: getTextureForMesh not needed here because we don't use texture filtering
|
||||
ref = tsrc->getTexture(p.string);
|
||||
|
||||
// Try to show another texture to indicate a code issue.
|
||||
if (!ref)
|
||||
ref = tsrc->getTexture("no_texture.png");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -455,14 +459,17 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius,
|
|||
} else {
|
||||
if (m_texpool.size() == 0)
|
||||
return;
|
||||
texture = ClientParticleTexRef(m_texpool[m_texpool.size() == 1 ? 0
|
||||
: myrand_range(0, m_texpool.size()-1)]);
|
||||
texture = ClientParticleTexRef(m_texpool[myrand_range(0, m_texpool.size() - 1)]);
|
||||
texpos = v2f(0.0f, 0.0f);
|
||||
texsize = v2f(1.0f, 1.0f);
|
||||
if (texture.tex->animated)
|
||||
pp.animation = texture.tex->animation;
|
||||
}
|
||||
|
||||
// Same guard as in `CE_SPAWN_PARTICLE`
|
||||
if (!texture.ref)
|
||||
return;
|
||||
|
||||
// synchronize animation length with particle life if desired
|
||||
if (pp.animation.type != TAT_NONE) {
|
||||
// FIXME: this should be moved into a TileAnimationParams class method
|
||||
|
@ -786,7 +793,8 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
|
|||
|
||||
const ParticleSpawnerParameters &p = *event->add_particlespawner.p;
|
||||
|
||||
// texture pool
|
||||
// There can be multiple textures, e.g. for time-based animations
|
||||
// Look up all required textures in `ITextureSource` to retrieve an `ITexture`.
|
||||
std::vector<ClientParticleTexture> texpool;
|
||||
if (!p.texpool.empty()) {
|
||||
size_t txpsz = p.texpool.size();
|
||||
|
|
|
@ -83,6 +83,9 @@ u32 PcgRandom::range(u32 bound)
|
|||
if (bound == 0)
|
||||
return next();
|
||||
|
||||
if (bound == 1)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
This is an optimization of the expression:
|
||||
0x100000000ull % bound
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue