   Crashing only on Hardware vertex processing
  So I was making a smallish, particle system.  It works if I specify software vertex processing, but if I turn on hardware processing, it crashes.I check to see if my card supports hardware vertex processing by using:m_pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps );//I test for the capabilityif( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ){ //setup for HW vertex processing }else{ //use software}when I run this code it errors out fairly quickly, I will comment the line I error out at where I get the temp pos from the iterator...void Particles::render(){HRESULT hr;if( !m_particles.empty() ){m_pdev->SetTexture( 0, m_partTex );m_pdev->SetFVF( FVFp );hr = m_pdev->SetStreamSource( 0, m_buffer, 0, sizeof( Particle ) );if( m_vbOffset >= m_vbSize )m_vbOffset = 0;Particle *temp;hr = m_buffer->Lock( 2 * m_vbOffset * sizeof( Particle ), 2 * m_batchSize * sizeof( Particle ), (void**)&temp, m_vbOffset ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD );DWORD nParticlesinBatch = 0;if( SUCCEEDED( hr ) ){std::vector< Attrib >::iterator it;for( it = m_particles.begin(); it != m_particles.end(); it++ ){if( it->isAlive ){temp->pos = it->pos; //we hit a unhandled exception here!temp->color = it->color;temp->FVF = FVFp;nParticlesinBatch++;if( nParticlesinBatch == m_batchSize * 2 ){m_buffer->Unlock();hr = m_pdev->DrawPrimitive( D3DPT_POINTLIST, m_vbOffset, m_batchSize * 2 );m_vbOffset += m_batchSize * 2;if( m_vbOffset >= m_vbSize )m_vbOffset = 0;hr = m_buffer->Lock( 2 * m_vbOffset * sizeof( Particle ), 2 * m_batchSize * sizeof( Particle ), (void**)&temp,m_vbOffset ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD );nParticlesinBatch = 0;}}}}m_buffer->Unlock();if( nParticlesinBatch ){m_pdev->DrawPrimitive( D3DPT_POINTLIST, m_vbOffset, nParticlesinBatch );}m_vbOffset += m_batchSize * 2;}}
  Go to Debug mode.for this line: temp->pos = it->pos; //we hit a unhandled exception here!what is the value of temp, and what is the value of it?   ;  temp becomes undefined because it cannot write to that location."it"(the iterator variable) still has valid data.  I.e. it has a randomly generated position that is valid, has color and all that.It seems that for some reason I am running off the memory I allocated for the vertexbuffer.  You wiull notice temp is a (void**) pointer for the buffer.But what exactly happening is not quite transparent to me. Sadly.   ;  I think that you should increase temp variable after checking if it->isAliveif( it->isAlive ){ temp->pos = it->pos; //we hit a unhandled exception here! temp->color = it->color; temp->FVF = FVFp; temp++; // thisIn your case you are writing always to one location because temp variable stays. Am I right? But this doesn't seems to be a problem source.also if( nParticlesinBatch == m_batchSize * 2 )try to:if( nParticlesinBatch >= m_batchSize * 2 )because if you don't hit that value you don't reset m_vbOffset and you may haverun out of scope. ;  Hmmm well I tried those out, it still crashes on hardware mode, same error.I retract what I said about incrementing temp, I was being shortsided.  Thanks, you improved what I was doing :) silly me forgetting to increment me the pointer to the memory :( bah.[Edited by - dpro on June 20, 2006 7:45:55 PM];  Another one mistake is that you are not handling second Lock, DrawPrimitves.Also I was not sure why you locking double of particles, so I removed it.Try this code (also don't forget to change definition in header because of HRESULT):HRESULT Particles::render(){HRESULT hr;if( !m_particles.empty() ){m_pdev->SetTexture( 0, m_partTex );m_pdev->SetFVF( FVFp );hr = m_pdev->SetStreamSource( 0, m_buffer, 0, sizeof( Particle ) );if( m_vbOffset >= m_vbSize )m_vbOffset = 0;Particle *temp;if( FAILED(hr = m_buffer->Lock(  m_vbOffset * sizeof( Particle ), m_batchSize * sizeof( Particle ), (void**)&temp, m_vbOffset ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ))){return hr;}DWORD nParticlesinBatch = 0;std::vector< Attrib >::iterator it;for( it = m_particles.begin(); it != m_particles.end(); it++ ){if( it->isAlive ){temp->pos = it->pos; //we hit a unhandled exception here!temp->color = it->color;temp->FVF = FVFp; // I don't think you need thistemp++;if( ++nParticlesinBatch == m_batchSize ){m_buffer->Unlock();if(FAILED(hr = m_pdev->DrawPrimitive( D3DPT_POINTLIST, m_vbOffset, m_batchSize))){return hr;}m_vbOffset += m_batchSize;if( m_vbOffset >= m_vbSize )m_vbOffset = 0;if(FAILED(hr = m_buffer->Lock(  m_vbOffset * sizeof( Particle ), m_batchSize * sizeof( Particle ), (void**)&temp,m_vbOffset ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ))){return hr;}nParticlesinBatch = 0;}}}}m_buffer->Unlock();if( nParticlesinBatch ){if(FAILED(hr = m_pdev->DrawPrimitive( D3DPT_POINTLIST, m_vbOffset, nParticlesinBatch )))return hr;}m_vbOffset += m_batchSize;return S_OK;}I don't think that problem is that your program doesn't works on PURE_HW.If I'm right you couldn't Lock vertex buffer if your graphical card doesn't support that, so on PURE_HW your program will exit from procedure before you can do anything. Somehow your temp variable go out of bonds and program tries to write in memory that's not reserved. That is the problem.Very offten the only problem/bug we can't resolve somehow is due to man factor. That kind of bugs that are before your eyes, but you could not seem them.   ;  This was me copying poorly from a book I own to test out particles.  You are right, it was the MAN factor, that is, I did not copy it the way it was written.  I must have been tired or been unable to read correctly when I was copying this. I am sure software mode was quietly keeping me from breaking things and adjusting so that what I wrote worked.  Edit:Well that was handy, as soon as I did what you suggested, it worked perfectly.  Thanks!  Need to pay more attention!Edit2:Hmm interesting, I ran with breakpoints, just to see if I hit one, I never did.  I wonder what happened to cause temp to run amok?  Its running in Hardware mode from what I can see.   