Repository navigation
fix(skills): Beast Uppercut no longer crashes when a bomb stone takes a fist's slot - #1148
Conversation
Mosch0512
left a comment
There was a problem hiding this comment.
Changes requested. The right fist no longer crashes, but the left fist still has the same crash, and the cause given in the comment and PR description is not what happens.
Required:
- The left fist (
Move_MODEL_DOWN_ATTACK_DUMMY_L) can still read a null owner (line 9342 comment). - The root-cause comment at 9383 is wrong (line 9383 comment).
- The left fist is created with
CreateEffectFpsChecked, so above 25 FPS it often never appears (line 9388 comment).
Non-blocking:
return truedrops the right fist's hit on the crash tick and runsMoveEffect's tail on the reused slot (line 9390 comment).- "Target not found" (index 400) now freezes the fists, and the target check is copied twice (line 9395 comment).
- Exit early instead of wrapping the body (line 9376 comment).
- Line 9337 keeps
|| !o->Owner->Live, which can't be true insideif (o->Owner != nullptr && o->Owner->Live); the PR removed the same dead check from the right fist. - A suggestion that fixes both fists in one way: mark the fist dead as the last step of the handler. Do the bomb, the trail, the flare and the owner follow first, then
OBJECT* owner = o->Owner; o->Live = false; CreateEffect(MODEL_DOWN_ATTACK_DUMMY_L, ...owner...); return false;. Then nothing can take the slot while the handler still useso, and the right fist keeps its hit.Move_BITMAP_SWORDEFF(9430-9455) has the same pattern: it setso->Live = false, then createsMODEL_SHOCKWAVE01, which can take the slot, ando->LifeTime = 45then lands on the new shockwave. No crash there, since every effect it creates gets the owner, but it is the same class of bug. - There is no test.
tests/effects(test_effect_creation.cpp,EffectRecorder) can driveCreateEffectandMoveEffecton the realEffectsarray. A test can make the fist's slot the lowest free one, setVelocity/AnimationFrameso the kill and the bomb fall on the same tick (LifeTime > 50, valid target), runMoveEffect, and check that the left fist was created and nothing read a null owner. That test fails today for the left fist.
| if (o->AnimationFrame >= 5.0f && o->LifeTime > 50) | ||
| { | ||
| if (o->Owner->m_sTargetIndex < 0) | ||
| if (o->Owner->m_sTargetIndex < 0 || o->Owner->m_sTargetIndex >= MAX_CHARACTERS_CLIENT) |
There was a problem hiding this comment.
Required. The left fist still has the crash this PR fixes in the right fist.
The null owner doesn't come from the left fist taking the slot (see the 9383 comment). It comes from CreateBomb3: it creates MODEL_STONE1/2 effects with no owner (ZzzEffect.cpp:5558/5561). If a fist has already set o->Live = false when it calls CreateBomb3, a stone can take its slot, and the handler then reads o->Owner of the stone.
The left fist does exactly that: line 9337 sets o->Live = false at frame >= 8, and this branch then calls CreateBomb3 on the same tick if the bomb hasn't fired yet. Then o->LifeTime = 40 is written to the stone, and VectorCopy(o->Owner->Angle, o->Angle) at 9354 reads through null.
When it happens: the left fist starts at frame 0 with LifeTime 100. At 25 FPS or less, with Velocity in [4, 5) (stamp PlaySpeed 2 to 2.5 from high attack speed), the handler sees frame 0, then 4.x (no bomb, below 5), then 8+: the kill and the first bomb on the same tick. The crash follows when no lower Effects slot is free. A target index that turns valid on the kill tick also triggers it. The null check at 9332 runs only at the start of the handler, so it doesn't help here.
| if (o->AnimationFrame >= 6.0f || !o->Owner->Live) | ||
| if (o->AnimationFrame >= 6.0f) | ||
| { | ||
| // The right fist is done; the left one follows. The new effect may take this very slot (it is |
There was a problem hiding this comment.
Required. This explanation isn't right, and it's why the left fist was missed.
CreateEffect always sets the new effect's owner (ZzzEffect.cpp:426-429: if (Owner) o->Owner = Owner;). If the left fist takes this slot, o->Owner is still the player, AnimationFrame is 0 and LifeTime is 100, so the old code skipped the bomb and read a valid owner at 9407. No crash.
The null comes from CreateBomb3's stones, created with no owner, taking the freed slot on a tick where the kill (frame >= 6) and the first bomb (frame >= 3, LifeTime > 50) happen together. That happens when the frame jumps from below 3 to 6+ in one tick (Velocity >= 6 at 25 FPS or less), or when the target becomes valid on the kill tick. That also fits the dumps: the null read is the VectorCopy(o->Owner->Angle, ...) after CreateJointFpsChecked, after the bomb branch ran. Please correct the comment (and the PR description) to name CreateBomb3's ownerless effects.
| OBJECT* owner = o->Owner; | ||
| o->Live = false; | ||
| CreateEffectFpsChecked(MODEL_DOWN_ATTACK_DUMMY_L, o->Owner->Position, o->Owner->Angle, o->Owner->Light, 0, o->Owner); | ||
| CreateEffectFpsChecked(MODEL_DOWN_ATTACK_DUMMY_L, owner->Position, owner->Angle, owner->Light, 0, |
There was a problem hiding this comment.
Required. Please use CreateEffect here. The right fist sets itself dead every time, but the left fist is only created when rand_fps_check(1) passes, which is true with probability 25/FPS (Random::ChanceOf(1, FPS_ANIMATION_FACTOR)). At 60 FPS that is 42% of casts; at 144 FPS about 17%. Every other cast has no second punch, no left-fist hit and no stamp sound.
This was CreateEffect until b0ed56c ("Added more fps checks for effects") changed it. That change fits effects spawned every tick, but this is a one-time creation. Since the PR rewrites this line, it's a one-word fix here.
| CreateEffectFpsChecked(MODEL_DOWN_ATTACK_DUMMY_L, o->Owner->Position, o->Owner->Angle, o->Owner->Light, 0, o->Owner); | ||
| CreateEffectFpsChecked(MODEL_DOWN_ATTACK_DUMMY_L, owner->Position, owner->Angle, owner->Light, 0, | ||
| owner); | ||
| return true; |
There was a problem hiding this comment.
Non-blocking. Two things about this return true:
- On the tick the PR is about (the kill and the first bomb on the same tick), the early return skips the frame-3 branch below. The right fist's
CreateBomb3hit andSOUND_RAGESKILL_STAMP_ATTACKnever play, and that tick's trail, flare and owner follow are skipped too. Before, they played whenever no stone took the slot. Marking the fist dead as the last step instead (see the review body) keeps them. truetellsMoveEffectto run its shared tail ono(ZzzEffect.cpp:5797-5802: a false return skips it). The tail callsPlayAnimationandMoveParticleonoand lowers itsLifeTime. If the left fist took this slot, that runs on the new left fist before its first handler tick, so the comment's "nothing ofois read after it" doesn't hold.return falsematches the intent.
| if (o->AnimationFrame >= 3.0f && o->LifeTime > 50) | ||
| { | ||
| if (o->Owner->m_sTargetIndex < 0) | ||
| if (o->Owner->m_sTargetIndex < 0 || o->Owner->m_sTargetIndex >= MAX_CHARACTERS_CLIENT) |
There was a problem hiding this comment.
Non-blocking. The upper bound doesn't stop an out-of-bounds read: CharactersClient has MAX_CHARACTERS_CLIENT + 1 entries (Winmain.cpp:2418-2419), and 400 is what FindCharacterIndex returns for "not found". What changes is that a target not found locally (e.g. out of view) now takes this early return true. That return skips the rest of the handler, not just the bomb, so for those ticks the fist stops following the player, loses its trail and flare, and plays no stamp sound. Guarding only the CreateBomb3 call (and still setting o->LifeTime = 40) avoids that. The same check is now copied into both fists (9342, 9395), while Move_BITMAP_SBUMB (9308), Move_BITMAP_SWORDEFF (9452) and MonkSystem.cpp index CharactersClient with the same field and check only < 0. A small helper that returns the target CHARACTER* or nullptr would give them one rule.
| Vector(1.f, 1.f, 1.f, Light); | ||
| { | ||
| if (o->Owner->Live) | ||
| if (o->Owner != nullptr && o->Owner->Live) |
There was a problem hiding this comment.
Non-blocking. This changed guard still wraps the whole handler. docs/CODING_RULES.md rule 2 says to prefer if (bad) return; over wrapping the entire body in if (good) { ... }, for new or changed code. For example: if (o->Owner == nullptr || !o->Owner->Live) { o->Live = false; return true; } at the top of both fists, and the else goes away.
…s the right one's slot The right fist's effect (MODEL_DOWN_ATTACK_DUMMY_R) set itself dead and then created the left fist's effect, which can take the very slot it just freed. It then went on with o->Owner, now the new effect's (still null), and crashed (access violation reading Owner->Angle). It now returns at once after it creates the left fist, and both fists check their owner and the target index.
CreateBomb3 creates MODEL_STONE1/2 effects without an owner. A fist which was already marked dead when it created its bomb could have its slot taken by such a stone, and the handler then read o->Owner through null. Both fists now keep their owner in a local and are marked dead at the end. The left fist is created with CreateEffect (a one-time creation; the FPS check dropped it on most casts above 25 FPS), and the right fist returns false afterwards so MoveEffect's shared tail does not run on it. A missing target now skips only the bomb. SkillTargetOf gives the Rage Fighter skill handlers one rule for the target index. Review feedback on Mutizens#1148. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60c6952 to
ede964a
Compare
|
Thanks for the careful review, you were right about the cause. I pushed the changes:
Tested on our fork with a high attack speed Fist Master: about 170 casts on Lorencia monsters and on Twin Tales in Kanturu Relics, no crash, and both punches play every time. The branch is rebased on current |
Mosch0512
left a comment
There was a problem hiding this comment.
Changes requested. Thanks, the fists look right now: they are marked dead as their last step, the left fist is created every time, and the cause is explained correctly. All three Required items from round 1 are fixed. One new problem comes from the helper, though.
Required:
- For a target that isn't in view (index 400),
SkillTargetOfnow returnsnullptr, and Chain Drive and Killing Blow stillreturn trueon that. So Chain Drive repeats its second hit on every tick, and Killing Blow plays none of its hit sounds (line 9494 and 9320 comments).
Non-blocking:
Move_BITMAP_SWORDEFF's first target read (9466-9469) wasn't moved to the helper. It still checks only< 0and usesCharactersClient[o->Owner->m_sTargetIndex], so index 400 createsBITMAP_DAMAGE1at the unused slot 400, while block 2 of the same handler treats 400 as "no target". The PR description says SWORDEFF uses the helper.- Old bug in the same block: with no target (
< 0), the earlyreturn trueat 9466-9467 comes after the twoCreateEffectFpsCheckedcalls but beforeo->LifeTime = 45. The block then runs again on every tick whileLifeTimefalls from 200 to 50 (up to about 6 s), creatingMODEL_SHOCKWAVE01andMODEL_WOLF_HEAD_EFFECT2each time. Guarding only theBITMAP_DAMAGE1creation fixes both points. - Old bug, same class as the fists:
Move_BITMAP_SWORDEFFsetso->Live = falseat 9443-9444 and then keeps creating effects and writing too, so a new shockwave can take the slot and geto->LifeTime = 45or20. It doesn't crash (every effect it creates gets the owner), but marking it dead last would fix it the same way as the fists. - Old bug:
MonkSystem.cpp:1253(Killing Blow, also 1385 and 1506) readsCharactersClient[_pObj->m_sTargetIndex]with no check, so a caster without a target reads before the array. - There is no automated test.
tests/effects(test_effect_creation.cpp,EffectRecorder) can driveCreateEffectandMoveEffect. A test could make the fist's slot the lowest free one, put the bomb and the end frame on one tick, and check that the left fist exists and no null owner was read. docs/PULL_REQUESTS.md: the fix changes what players see (the second punch now always appears), so the description needs a short before/after video, a line saying the crash or the missing punch was reproduced on main first, a "not tested" line and the coding-rules confirmation.
The red CI isn't from this PR: main fails the same Magic Skeleton cloth test since #996.
| CreateEffectFpsChecked(MODEL_SHOCKWAVE_SPIN01, vPosition, Angle, Light, 1, o->Owner, -1, 0, 0, 0, 0.9f); | ||
|
|
||
| if (o->Owner->m_sTargetIndex < 0) | ||
| const CHARACTER* target = SkillTargetOf(o->Owner); |
There was a problem hiding this comment.
Required. For a target that isn't in view, this now repeats the whole block on every tick.
SkillTargetOf returns nullptr for index 400 (FindCharacterIndex's "not found"). The return true here comes before o->LifeTime = 20, so while the owner's frame is above 11 and LifeTime above 20 (about 25 ticks after block 1 set it to 45), every tick creates MODEL_SHOCKWAVE02, MODEL_WOLF_HEAD_EFFECT2 and two MODEL_SHOCKWAVE_SPIN01 again, and SOUND_RAGESKILL_GIANTSWING_ATTACK never plays. Before this PR, index 400 ran the block once.
Same as in the fists: guard only the BITMAP_SHINY + 4 creation with the target, and keep the sound and o->LifeTime = 20 outside the guard.
| vec3_t vLight, vPosition; | ||
| Vector(1.0f, 1.0f, 1.0f, vLight); | ||
| if (o->Owner->m_sTargetIndex < 0) | ||
| const CHARACTER* target = SkillTargetOf(o->Owner); |
There was a problem hiding this comment.
Required (same point as the 9494 comment). With index 400 this now returns before the sound block at 9330. The effect is in this branch at LifeTime 15, 9 and 6, so none of Killing Blow's three SOUND_RAGESKILL_THRUST_ATTACK plays when the target isn't in view; before this PR they played. Guard only the particle creation and let the function go on to the sounds.
| return true; | ||
| } | ||
|
|
||
| // The character a skill's owner is aiming at, or nullptr when it has none or it isn't in view |
There was a problem hiding this comment.
Non-blocking. "or it isn't in view" is more than this checks: it only rejects the "not found" index. A target that left the view (or died) after the index was stored still comes back, even if its slot is now dead or holds another character, so the bomb can land on whoever took the slot. Either also return nullptr when !CharactersClient[index].Object.Live, or say in the comment that only the "not found" index is rejected.
… without a target in view Review round 2: SkillTargetOf's nullptr now guards only what is created at the target. Chain Drive's second blow no longer repeats every tick and Killing Blow's thrust sounds play when the target isn't in view. Chain Drive's first blow uses the helper too (index 400 no longer creates BITMAP_DAMAGE1 at slot 400, and no target no longer repeats the first blow), and its effect is marked dead as its last step. SkillTargetOf also rejects a slot whose character is gone. Tests: test_rage_skill_targets.
|
Thanks, good catch on the early returns. Pushed 5bfdeec: Required
Non-blocking, also done
Not in this PR
|
Mosch0512
left a comment
There was a problem hiding this comment.
Approved. Thanks, everything from round 2 is fixed: the targets out of view, Chain Drive's first blow and its "dead last" order, the Live check in SkillTargetOf, and there is a test now. CI is green. The points below are Non-blocking; fixing them here or in a follow-up is fine.
Non-blocking:
Move_BITMAP_SWORDEFF(old code) still readso->Ownerwith no null orLivecheck, unlike the fists now. The guard the fists got at the top would end it cleanly if the owner goes.MonkSystem.cpp:1253(old code, also 1385 and 1506):RageCreateEffectstill readsCharactersClient[_pObj->m_sTargetIndex]unchecked when the skill is cast. With no target it reads before the array.SkillTargetOfin a header would cover it.- Test nits: see the three inline comments.
docs/PULL_REQUESTS.md: a short before/after clip (Beast Uppercut at high FPS, second punch missing before) would still be good.
| Models = previousModels; | ||
| } | ||
|
|
||
| static void ClearPools() |
There was a problem hiding this comment.
Non-blocking. ClearPools clears Effects and Particles but not the Joints. Chain Drive's handler creates BITMAP_SWORDEFF joints whose Target is this scope's caster, and the scope frees characters when it ends, so those joints keep a dangling Target. Nothing in this binary moves joints today, but a later test that does would read freed memory. Clearing Joints (and g_SkillEffects) here too avoids that.
| EffectTestData::BuildShippedRegistry(); | ||
| Models = models.get(); | ||
| CharactersClient = characters.get(); | ||
| Hero = nullptr; |
There was a problem hiding this comment.
Non-blocking. With Hero = nullptr, every CreateEffect goes through CSkillEffectMgr::IsSkillEffect, which evaluates Owner != &Hero->Object. Taking a member's address through a null pointer is undefined behaviour: it works today, but a UBSan build would flag it. Pointing Hero at a test-owned CHARACTER (as tests/data/HeroScope.h does) avoids it.
| for (int move = 0; move < 10; ++move) | ||
| MoveEffects(); | ||
| CHECK(scope.audio.Plays(SOUND_RAGESKILL_GIANTSWING_ATTACK) == 2); | ||
| CHECK(LiveEffects(MODEL_SHOCKWAVE01) <= 1); |
There was a problem hiding this comment.
Non-blocking. A shockwave lives only a few ticks, so a handler that re-creates one every tick still keeps about one alive at a time, and <= 1 passes. Only the sound count catches a repeat here. Counting creations (for example the number of shockwaves created over the ten moves) would make this check catch it too.
Bug
Casting the Rage Fighter's Beast Uppercut can crash the client (access violation,
0xC0000005).Three crash dumps all point to the same instruction in
Move_MODEL_DOWN_ATTACK_DUMMY_R(src/source/Render/Effects/Behaviors/MoveHandlers.cpp): a read ofOwner->Angle(offset0x120) through a nullo->Owner, right afterCreateJointFpsChecked(BITMAP_FORCEPILLAR, ...).Cause
CreateBomb3createsMODEL_STONE1/2effects without an owner (ZzzEffect.cpp). A fist marks itself dead (o->Live = false) when its animation ends: the right fist at frame 6, the left fist at frame 8. If that happens on the same tick as its bomb (frame 3 for the right fist, frame 5 for the left one),CreateBomb3runs while the fist's slot is already free, and a stone can take it. The handler then goes on witho, which is now the stone: it writesLifeTimeinto the stone and readso->Owner->Anglethrough null.That tick happens when the frame jumps over the bomb frame and the end frame at once (high attack speed at a low frame rate), or when the target becomes valid on the end tick. It fits the dumps: the null read is the
VectorCopy(o->Owner->Angle, ...)after the bomb branch ran.Fix
o.CreateEffectinstead ofCreateEffectFpsChecked: it is a one-time creation, and the FPS check dropped the second punch, its hit and its sound on most casts above 25 FPS. After creating it, the handler returnsfalse, soMoveEffect's shared tail doesn't run on the new effect if it took the slot.SkillTargetOf, returns the owner's targetCHARACTER*, ornullptrfor no target,FindCharacterIndex's "not found" (400) or a slot whose character is gone. Every user guards only what it creates at the target: the fists'CreateBomb3, Killing Blow's particles (Move_BITMAP_SBUMB), Chain Drive'sBITMAP_DAMAGE1andBITMAP_SHINY + 4(Move_BITMAP_SWORDEFF) andMove_BITMAP_DAMAGE1's particles. Sounds andLifeTimesteps run either way, so no blow repeats and no sound is lost without a target.Move_BITMAP_SWORDEFFis marked dead as its last step too.Changes:
MoveHandlers.cpp, and a new test (tests/effects/test_rage_skill_targets.cpp).Before / After
No video. The fix is checked by the new test (it fails on the previous commit) and in game (Beast Uppercut and Chain Drive cast 36 times on Twin Tales, no crash).
Testing
o->Ownerread inMove_MODEL_DOWN_ATTACK_DUMMY_R). Not reproduced on currentmain.test_rage_skill_targetspasses (4 cases, 30 checks); 3 of its cases fail on the previous commit.test_phoenix_shotstill passes.scripts/check_format.shpasses (clang-format 21.1.8).Coding rules
I read
docs/CODING_RULES.mdanddocs/PULL_REQUESTS.mdand followed them for this change.🤖 Generated with Claude Code