Firlefanz
30-10-2005, 08:21 AM
Hello,
in my Game demo one of my Beta testers has a bug in a 3D sequence, the screens freezes, but in the background it continues.
I cannot reproduze this error myself, everything fine here.
I build in some error messages to find out where the errors come from.
They are coming from my 3D Particles. I included them from the SDK sample.
So here is the code how I render those particles (please not exceptionmsg is a function that writes the string into a textfile):
function CParticleSystem.Render(pd3dDevice: IDirect3DDevice9;nsize: single): HResult;
var
p_Particle: P3DParticle;
pVertices: PPointVertex;
dwNumParticlesToRender: DWord;
Flags: DWord;
vPos, vVel: TD3DXVector3;
fLengthSq: Single;
dwSteps: DWord;
clrDiffuse: TD3DXColor;
dwDiffuse: DWORD;
i: Integer;
begin
try
// Set the render states for using point sprites
pd3dDevice.SetRenderState(D3DRS_POINTSPRITEENABLE, iTRUE);
pd3dDevice.SetRenderState(D3DRS_POINTSCALEENABLE, iTRUE);
pd3dDevice.SetRenderState(D3DRS_POINTSIZE, FtoDW(nsize)); //GrA¬?AYe Partikel
pd3dDevice.SetRenderState(D3DRS_POINTSIZE_MIN, FtoDW(0.01));
pd3dDevice.SetRenderState(D3DRS_POINTSCALE_A, FtoDW(0.01));
pd3dDevice.SetRenderState(D3DRS_POINTSCALE_B, FtoDW(0.01));
pd3dDevice.SetRenderState(D3DRS_POINTSCALE_C, FtoDW(1.00));
// Set up the vertex buffer to be rendered
pd3dDevice.SetStreamSource(0, m_pVB, SizeOf(TPointVertex),SizeOf(TPointVertex)); //dx9 letzter Param size in byte
pd3dDevice.SetFVF(D3DFVF_POINTVERTEX);
if m_pParticles=nil then exit;
p_Particle := m_pParticles;
if p_particle=nil then exit;
dwNumParticlesToRender := 0;
// Lock the vertex buffer. We fill the vertex buffer in small
// chunks, using D3DLOCK_NOOVERWRITE. When we are done filling
// each chunk, we call DrawPrim, and lock the next chunk. When
// we run out of space in the vertex buffer, we start over at
// the beginning, using D3DLOCK_DISCARD.
Inc(m_dwBase, m_dwFlush);
if (m_dwBase >= m_dwDiscard) then m_dwBase:= 0;
if m_dwBase = 0 then Flags:= D3DLOCK_DISCARD else Flags:= D3DLOCK_NOOVERWRITE;
if m_pvb=nil then exit;
if failed(m_pVB.Lock(m_dwBase * SizeOf(TPointVertex), m_dwFlush * SizeOf(TPointVertex),
Pointer(pVertices), Flags)) then begin
commandoform.ExceptionMsg('ParticleLock');
exit;
end;
// Render each particle
while Assigned(p_Particle) do
begin
vPos:= p_Particle.m_vPos;
vVel:= p_Particle.m_vVel;
fLengthSq := D3DXVec3LengthSq(vVel);
if (fLengthSq < 1.0) then dwSteps := 2
else if (fLengthSq < 4.00) then dwSteps := 3
else if (fLengthSq < 9.00) then dwSteps := 4
else if (fLengthSq < 12.25) then dwSteps := 5
else if (fLengthSq < 16.00) then dwSteps := 6
else if (fLengthSq < 20.25) then dwSteps := 7
else dwSteps := 8;
D3DXVec3Scale(vVel, vVel, -0.04 / dwSteps);
D3DXColorLerp(clrDiffuse, p_Particle.m_clrFade, p_Particle.m_clrDiffuse, p_Particle.m_fFade);
dwDiffuse:= D3DXColorToDWord(clrDiffuse);
// Render each particle a bunch of times to get a blurring effect
for i:= 0 to dwSteps - 1 do
begin
pVertices.v := vPos;
pVertices.color := dwDiffuse;
Inc(pVertices);
Inc(dwNumParticlesToRender);
if (dwNumParticlesToRender = m_dwFlush) then
begin
// Done filling this chunk of the vertex buffer. Lets unlock and
// draw this portion so we can begin filling the next chunk.
if failed(m_pVB.Unlock) then begin
commandoform.exceptionmsg('ParticleUnLock');
exit;
end;
Result:= pd3dDevice.DrawPrimitive(D3DPT_POINTLIST, m_dwBase, dwNumParticlesToRender);
if FAILED(Result) then begin
commandoform.exceptionmsg('Rendererror DrawPrimitive');
Exit;
end;
// Lock the next chunk of the vertex buffer. If we are at the
// end of the vertex buffer, DISCARD the vertex buffer and start
// at the beginning. Otherwise, specify NOOVERWRITE, so we can
// continue filling the VB while the previous chunk is drawing.
Inc(m_dwBase, m_dwFlush);
if (m_dwBase >= m_dwDiscard) then m_dwBase:= 0;
if m_dwBase = 0 then Flags:= D3DLOCK_DISCARD else Flags:= D3DLOCK_NOOVERWRITE;
if failed(m_pVB.Lock(m_dwBase * SizeOf(TPointVertex), m_dwFlush * SizeOf(TPointVertex),
Pointer(pVertices), Flags)) then begin
commandoform.exceptionmsg('ParticleLock2');
exit;
end;
dwNumParticlesToRender := 0;
end;
D3DXVec3Add(vPos, vPos, vVel);
end;
if p_Particle.m_pNext=nil then exit;
p_Particle := p_Particle.m_pNext;
end;
// Unlock the vertex buffer
m_pVB.Unlock;
// Render any remaining particles
if (dwNumParticlesToRender <> 0) then
begin
Result:= pd3dDevice.DrawPrimitive(D3DPT_POINTLIST, m_dwBase, dwNumParticlesToRender);
if FAILED(Result) then Exit;
end;
// Reset render states
pd3dDevice.SetRenderState(D3DRS_POINTSPRITEENABLE, iFALSE);
pd3dDevice.SetRenderState(D3DRS_POINTSCALEENABLE, iFALSE);
Result := S_OK;
except
commandoform.exceptionmsg('Rendererror Particles');
end;
end;
My betatester reports the error is Particlelock and then it freezes.
Here is the code I use to render the particles:
//fA¼r partikel setzen
setrenderstate(d3drs_alphablendenable,dword(true)) ;
setrenderstate(d3drs_srcblend,d3dblend_srcalpha);
setrenderstate(d3drs_destblend,d3dblend_destalpha) ;
setmaterial(m_pParticleMaterial);
try
if m_pParticleTexture<>nil then SetTexture(0, m_pParticleTexture )
else exceptionmsg('3D Particle Nil');
except
exceptionmsg('3D Particle Error');
end;
setTextureStageState(0, D3DTSS_COLORARG1, D3DTA_Texture);
setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_selectarg1);
setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_disable);
m_pParticleSystem.Render(XenScreen.Device,0.3);
setrenderstate(d3drs_alphablendenable,dword(false) );
setrenderstate(d3drs_specularenable,dword(false));
//fA¼r skybox setzen
setTextureStageState(0, D3DTSS_COLOROP, d3dtop_modulate);
setTextureStageState(1, D3DTSS_COLOROP, d3dtop_modulate);
setRenderState(D3DRS_NORMALIZENORMALS, 0);
setTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU or 1);
setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
So do you have any idea, how to fix that bug?
I have a htm file with the devicecaps of my testers graficx card here:
http://www.ericbehme.de/download/DeviceCaps.htm
Any idea how to fix that error or at least make the screen not freeze or what to do next?
Thanks a lot,
Firle
in my Game demo one of my Beta testers has a bug in a 3D sequence, the screens freezes, but in the background it continues.
I cannot reproduze this error myself, everything fine here.
I build in some error messages to find out where the errors come from.
They are coming from my 3D Particles. I included them from the SDK sample.
So here is the code how I render those particles (please not exceptionmsg is a function that writes the string into a textfile):
function CParticleSystem.Render(pd3dDevice: IDirect3DDevice9;nsize: single): HResult;
var
p_Particle: P3DParticle;
pVertices: PPointVertex;
dwNumParticlesToRender: DWord;
Flags: DWord;
vPos, vVel: TD3DXVector3;
fLengthSq: Single;
dwSteps: DWord;
clrDiffuse: TD3DXColor;
dwDiffuse: DWORD;
i: Integer;
begin
try
// Set the render states for using point sprites
pd3dDevice.SetRenderState(D3DRS_POINTSPRITEENABLE, iTRUE);
pd3dDevice.SetRenderState(D3DRS_POINTSCALEENABLE, iTRUE);
pd3dDevice.SetRenderState(D3DRS_POINTSIZE, FtoDW(nsize)); //GrA¬?AYe Partikel
pd3dDevice.SetRenderState(D3DRS_POINTSIZE_MIN, FtoDW(0.01));
pd3dDevice.SetRenderState(D3DRS_POINTSCALE_A, FtoDW(0.01));
pd3dDevice.SetRenderState(D3DRS_POINTSCALE_B, FtoDW(0.01));
pd3dDevice.SetRenderState(D3DRS_POINTSCALE_C, FtoDW(1.00));
// Set up the vertex buffer to be rendered
pd3dDevice.SetStreamSource(0, m_pVB, SizeOf(TPointVertex),SizeOf(TPointVertex)); //dx9 letzter Param size in byte
pd3dDevice.SetFVF(D3DFVF_POINTVERTEX);
if m_pParticles=nil then exit;
p_Particle := m_pParticles;
if p_particle=nil then exit;
dwNumParticlesToRender := 0;
// Lock the vertex buffer. We fill the vertex buffer in small
// chunks, using D3DLOCK_NOOVERWRITE. When we are done filling
// each chunk, we call DrawPrim, and lock the next chunk. When
// we run out of space in the vertex buffer, we start over at
// the beginning, using D3DLOCK_DISCARD.
Inc(m_dwBase, m_dwFlush);
if (m_dwBase >= m_dwDiscard) then m_dwBase:= 0;
if m_dwBase = 0 then Flags:= D3DLOCK_DISCARD else Flags:= D3DLOCK_NOOVERWRITE;
if m_pvb=nil then exit;
if failed(m_pVB.Lock(m_dwBase * SizeOf(TPointVertex), m_dwFlush * SizeOf(TPointVertex),
Pointer(pVertices), Flags)) then begin
commandoform.ExceptionMsg('ParticleLock');
exit;
end;
// Render each particle
while Assigned(p_Particle) do
begin
vPos:= p_Particle.m_vPos;
vVel:= p_Particle.m_vVel;
fLengthSq := D3DXVec3LengthSq(vVel);
if (fLengthSq < 1.0) then dwSteps := 2
else if (fLengthSq < 4.00) then dwSteps := 3
else if (fLengthSq < 9.00) then dwSteps := 4
else if (fLengthSq < 12.25) then dwSteps := 5
else if (fLengthSq < 16.00) then dwSteps := 6
else if (fLengthSq < 20.25) then dwSteps := 7
else dwSteps := 8;
D3DXVec3Scale(vVel, vVel, -0.04 / dwSteps);
D3DXColorLerp(clrDiffuse, p_Particle.m_clrFade, p_Particle.m_clrDiffuse, p_Particle.m_fFade);
dwDiffuse:= D3DXColorToDWord(clrDiffuse);
// Render each particle a bunch of times to get a blurring effect
for i:= 0 to dwSteps - 1 do
begin
pVertices.v := vPos;
pVertices.color := dwDiffuse;
Inc(pVertices);
Inc(dwNumParticlesToRender);
if (dwNumParticlesToRender = m_dwFlush) then
begin
// Done filling this chunk of the vertex buffer. Lets unlock and
// draw this portion so we can begin filling the next chunk.
if failed(m_pVB.Unlock) then begin
commandoform.exceptionmsg('ParticleUnLock');
exit;
end;
Result:= pd3dDevice.DrawPrimitive(D3DPT_POINTLIST, m_dwBase, dwNumParticlesToRender);
if FAILED(Result) then begin
commandoform.exceptionmsg('Rendererror DrawPrimitive');
Exit;
end;
// Lock the next chunk of the vertex buffer. If we are at the
// end of the vertex buffer, DISCARD the vertex buffer and start
// at the beginning. Otherwise, specify NOOVERWRITE, so we can
// continue filling the VB while the previous chunk is drawing.
Inc(m_dwBase, m_dwFlush);
if (m_dwBase >= m_dwDiscard) then m_dwBase:= 0;
if m_dwBase = 0 then Flags:= D3DLOCK_DISCARD else Flags:= D3DLOCK_NOOVERWRITE;
if failed(m_pVB.Lock(m_dwBase * SizeOf(TPointVertex), m_dwFlush * SizeOf(TPointVertex),
Pointer(pVertices), Flags)) then begin
commandoform.exceptionmsg('ParticleLock2');
exit;
end;
dwNumParticlesToRender := 0;
end;
D3DXVec3Add(vPos, vPos, vVel);
end;
if p_Particle.m_pNext=nil then exit;
p_Particle := p_Particle.m_pNext;
end;
// Unlock the vertex buffer
m_pVB.Unlock;
// Render any remaining particles
if (dwNumParticlesToRender <> 0) then
begin
Result:= pd3dDevice.DrawPrimitive(D3DPT_POINTLIST, m_dwBase, dwNumParticlesToRender);
if FAILED(Result) then Exit;
end;
// Reset render states
pd3dDevice.SetRenderState(D3DRS_POINTSPRITEENABLE, iFALSE);
pd3dDevice.SetRenderState(D3DRS_POINTSCALEENABLE, iFALSE);
Result := S_OK;
except
commandoform.exceptionmsg('Rendererror Particles');
end;
end;
My betatester reports the error is Particlelock and then it freezes.
Here is the code I use to render the particles:
//fA¼r partikel setzen
setrenderstate(d3drs_alphablendenable,dword(true)) ;
setrenderstate(d3drs_srcblend,d3dblend_srcalpha);
setrenderstate(d3drs_destblend,d3dblend_destalpha) ;
setmaterial(m_pParticleMaterial);
try
if m_pParticleTexture<>nil then SetTexture(0, m_pParticleTexture )
else exceptionmsg('3D Particle Nil');
except
exceptionmsg('3D Particle Error');
end;
setTextureStageState(0, D3DTSS_COLORARG1, D3DTA_Texture);
setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_selectarg1);
setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_disable);
m_pParticleSystem.Render(XenScreen.Device,0.3);
setrenderstate(d3drs_alphablendenable,dword(false) );
setrenderstate(d3drs_specularenable,dword(false));
//fA¼r skybox setzen
setTextureStageState(0, D3DTSS_COLOROP, d3dtop_modulate);
setTextureStageState(1, D3DTSS_COLOROP, d3dtop_modulate);
setRenderState(D3DRS_NORMALIZENORMALS, 0);
setTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU or 1);
setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
So do you have any idea, how to fix that bug?
I have a htm file with the devicecaps of my testers graficx card here:
http://www.ericbehme.de/download/DeviceCaps.htm
Any idea how to fix that error or at least make the screen not freeze or what to do next?
Thanks a lot,
Firle