the Owens crash: a device reset that never waited for the device (#35)
Eight byte-identical field stacks from night 6, all one player, all in an
Owens: ParticleEngine::Destroy +0x11, access=0 target=0x0, from the plain
per-frame render path. Nothing in the stack touches weapons or the Owens.
Conn Man's Surface Pro 9 (Iris Xe, 128 MB shared) is simply the only GPU in
the fleet that ever actually LOSES the D3D9 device -- his two-trigger
missile+laser bursts are what provoke the timeout, not what crashes.
What crashed is our device-loss handling, which was wrong three ways at once,
in two inline copies (the scene Present and the wait-screen Present):
1. On D3DERR_DEVICELOST it called Reset() IMMEDIATELY. Reset on a
still-lost device ALWAYS fails, and V() only logs. There was no
TestCooperativeLevel gate at all.
2. It then ran ParticleEngine::Initialize against the lost device. The
creates fail there and NULL their out-params -- proven, not assumed:
the bench repro faults at target=0x0, not at a dangling address.
3. The next lost frame called ParticleEngine::Destroy again, which
Release()d those NULLs blind. Read of vtable at 0x0. Dead.
So: lost frame 1 tears down and leaves NULLs, lost frame 2 crashes. Two
frames, every time, deterministic -- which is exactly why all 8 field stacks
are byte-identical.
Reproduced before fixing. BT_DEVICELOST_TEST=<frame>,crashrepro runs the
field sequence on the bench; on the unfixed build it died at Destroy +0x11,
access=0 target=0x0, and symbolized to the same four frames as the field
logs. Same shape, same offsets-modulo-hook. That run also proved the
out-param-nulling assumption the whole diagnosis rested on.
The fix -- one shared DPLRenderer::BTResetLostDevice() replacing both inline
copies:
- Destroy() is idempotent and null-safe, and nulls after release.
- Reset() is gated on TestCooperativeLevel() != D3DERR_DEVICELOST; while
the driver still says lost, skip the frame and retry.
- The Reset HRESULT is checked; on failure, log and retry next frame
instead of driving on.
- On success, re-create via the new CreateDeviceObjects(), NOT
Initialize(): Initialize memsets the installed-effects table, so every
reset that DID succeed silently killed all particle effects for the rest
of the mission. The quieter sibling bug, fixed by the same split.
- Initialize checks its HRESULTs and defends MAXPARTICLES<=0; the draw
paths guard the NULL buffer, and ExecuteParticles keeps draining
particles while the engine is dormant so they cannot pile up.
Verified: the crashrepro shape now logs SURVIVED and play continues; three
forced full loss/reset cycles each log "[render] device reset OK"; a plain
run is assert-free.
Found while verifying, worth its own line: VIDEO\particles.png has NEVER
existed -- not in the tree, not in BTL4.RES, not anywhere in git history.
The texture load has failed on every machine since the engine was written,
and every billboard particle ever rendered was untextured quads via
SetTexture(0, NULL). RenderParticles deliberately does NOT gate on the
texture -- that would disable all particles everywhere; untextured IS the
shipped look. Filed separately; a real particle sheet is a content task.
The field verification that counts is Conn Man flying his exact crash
loadout on this build: instead of a dead process he should see at worst a
brief hitch and "[render] device reset OK" in his log. #35 stays open until
that happens.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
4c7f6fd9b1
commit
dca2586aa8
@@ -1,5 +1,7 @@
|
||||
#include "l4particles.h"
|
||||
#include "../munga/time.h"
|
||||
#include "../munga/style.h" // DEBUG_STREAM (#35 diagnostics)
|
||||
#include <iostream>
|
||||
|
||||
LPDIRECT3DDEVICE9 ParticleEngine::mDevice = NULL;
|
||||
PARTICLE_EFFECT ParticleEngine::mInstalledEffects[MAX_PARTICLE_EFFECTS];
|
||||
@@ -251,26 +253,89 @@ void ParticleEmitter::Execute()
|
||||
|
||||
void ParticleEngine::Destroy()
|
||||
{
|
||||
mVertBuffer->Release();
|
||||
mParticleTexture->Release();
|
||||
// #35 (the field "Owens crash"). This runs on the DEVICELOST path, and a
|
||||
// device can stay lost for several frames -- so this must be idempotent
|
||||
// and null-safe. It used to Release() blind: the first lost frame
|
||||
// released the buffer, the failed re-create on the still-lost device left
|
||||
// both statics NULL, and the SECOND lost frame's Release() read the
|
||||
// vtable at 0x0 (8/8 field stacks byte-identical at Destroy +0x11;
|
||||
// reproduced on the bench with BT_DEVICELOST_TEST=<n>,crashrepro).
|
||||
if (mVertBuffer != NULL)
|
||||
{
|
||||
mVertBuffer->Release();
|
||||
mVertBuffer = NULL;
|
||||
}
|
||||
if (mParticleTexture != NULL)
|
||||
{
|
||||
mParticleTexture->Release();
|
||||
mParticleTexture = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleEngine::Initialize(LPDIRECT3DDEVICE9 device)
|
||||
{
|
||||
mDevice = device;
|
||||
// Full STARTUP init only. The device-reset path must use
|
||||
// CreateDeviceObjects() below -- coming through here would memset the
|
||||
// installed-effects table and kill every particle effect for the rest of
|
||||
// the mission (#35's quieter sibling).
|
||||
memset(mInstalledEffects, 0, sizeof(mInstalledEffects));
|
||||
|
||||
ParticleEngine::mMaxParticleCount = atoi(getenv("MAXPARTICLES"));
|
||||
|
||||
// create the vertex buffer that will store the four vertices we need for the billboards
|
||||
mDevice->CreateVertexBuffer(ParticleEngine::mMaxParticleCount * 6 * sizeof(L4BASICVERTEX),
|
||||
const char *max_env = getenv("MAXPARTICLES");
|
||||
ParticleEngine::mMaxParticleCount = (max_env != NULL) ? atoi(max_env) : 0;
|
||||
if (ParticleEngine::mMaxParticleCount <= 0)
|
||||
ParticleEngine::mMaxParticleCount = 8192; // btl4main defaults the env; belt + braces
|
||||
|
||||
CreateDeviceObjects(device);
|
||||
}
|
||||
|
||||
void ParticleEngine::CreateDeviceObjects(LPDIRECT3DDEVICE9 device)
|
||||
{
|
||||
// (Re)create the D3D resources. #35: CHECK the HRESULTs -- on a lost
|
||||
// device (or an out-of-video-memory iGPU, the field machine is a 128 MB
|
||||
// Iris Xe) these FAIL and null their out params; the old code drove
|
||||
// straight on, and the NULLs then killed the next Destroy(). On failure
|
||||
// we log and leave the engine dormant -- Execute/Render guard on the
|
||||
// NULLs, particles drain but don't draw -- and the next successful reset
|
||||
// brings it back.
|
||||
mDevice = device;
|
||||
|
||||
mVertBuffer = NULL;
|
||||
mParticleTexture = NULL;
|
||||
|
||||
// create the vertex buffer that will store the six vertices we need for the billboards
|
||||
HRESULT hr = mDevice->CreateVertexBuffer(
|
||||
ParticleEngine::mMaxParticleCount * 6 * sizeof(L4BASICVERTEX),
|
||||
D3DUSAGE_DYNAMIC,
|
||||
L4BASICVERTEX_FVF,
|
||||
D3DPOOL_DEFAULT,
|
||||
&mVertBuffer,
|
||||
NULL);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
mVertBuffer = NULL; // belt + braces vs runtime behavior
|
||||
DEBUG_STREAM << "[particles] CreateVertexBuffer FAILED hr=0x"
|
||||
<< std::hex << (unsigned long)hr << std::dec
|
||||
<< " (max=" << ParticleEngine::mMaxParticleCount
|
||||
<< ") -- particles dormant until the next successful reset"
|
||||
<< std::endl << std::flush;
|
||||
}
|
||||
|
||||
D3DXCreateTextureFromFile(mDevice, L"VIDEO\\particles.png", &mParticleTexture);
|
||||
// NB: VIDEO\particles.png has never shipped (verified 2026-07-29: absent
|
||||
// from the tree, the RES, and all of git history), so this load has
|
||||
// failed on every machine since the engine was written and particles
|
||||
// draw untextured. The failure is expected + logged once; rendering
|
||||
// proceeds without the texture (SetTexture(0, NULL) = the shipped look).
|
||||
hr = D3DXCreateTextureFromFile(mDevice, L"VIDEO\\particles.png", &mParticleTexture);
|
||||
if (FAILED(hr))
|
||||
mParticleTexture = NULL;
|
||||
|
||||
if (mVertBuffer != NULL)
|
||||
{
|
||||
DEBUG_STREAM << "[particles] device objects created (max="
|
||||
<< ParticleEngine::mMaxParticleCount
|
||||
<< ", texture=" << (mParticleTexture != NULL ? "loaded" : "MISSING (untextured quads -- the shipped look)")
|
||||
<< ")" << std::endl << std::flush;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleEngine::InstallEffect(int effectNumber, PARTICLE_EFFECT effect)
|
||||
@@ -453,6 +518,12 @@ void ParticleEngine::ExecuteParticles(const D3DXMATRIX *view_matrix, Scalar time
|
||||
}
|
||||
}
|
||||
|
||||
// #35: with the device objects torn down (device lost mid-reset) the
|
||||
// update/expire loop above must still run -- particles keep draining --
|
||||
// but there is no buffer to build into.
|
||||
if (mVertBuffer == NULL)
|
||||
return;
|
||||
|
||||
// now we're going to sort the particle list based on distance to the camera
|
||||
mergesort(&mParticlesHead, &mParticlesTail, view_matrix);
|
||||
|
||||
@@ -484,7 +555,14 @@ void ParticleEngine::RenderParticles(const D3DXMATRIX *view_matrix, Scalar timeS
|
||||
// variables get all screwed up when we don't run for a while
|
||||
ExecuteParticles(view_matrix, timeSlice);
|
||||
|
||||
if (!mDevice || mTotalParticleCount <= 0)
|
||||
// (#35: the buffer is legitimately NULL while the device is lost. The
|
||||
// TEXTURE is deliberately NOT part of this gate: VIDEO\particles.png has
|
||||
// never existed -- not in the tree, the RES, or git history -- so
|
||||
// mParticleTexture has been NULL on every machine since the engine was
|
||||
// written, and SetTexture(0, NULL) drawing untextured quads IS the
|
||||
// shipped look. Gating on it would silently disable all billboard
|
||||
// particles everywhere.)
|
||||
if (!mDevice || mVertBuffer == NULL || mTotalParticleCount <= 0)
|
||||
return;
|
||||
|
||||
// setup stages for particle's texture
|
||||
|
||||
Reference in New Issue
Block a user