This topic is now archived and is closed to further replies.


Runtime crash when calling SetStreamSource...

Recommended Posts

Silex    140
I have a terrain class that renders fine and I'm trying to add point sprites above each patch ( diamond) of the terrain. I have it set up so the terrain is rendered first using a mesh, then I set the stream to the vertex buffer containing the point sprites. The program compiles fine, but when I run it it crashes and the debugger points me to the line where I'm assigning the point sprite VB to the device stream. Here's the function that's supposed to draw the point sprites:
void Terrain::drawNodes()
	_device->SetRenderState(D3DRS_LIGHTING, false);
	_device->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
	_device->SetRenderState(D3DRS_POINTSCALEENABLE, true); 
	_device->SetRenderState(D3DRS_POINTSIZE, d3d::FtoDw(0.25f));
	_device->SetRenderState(D3DRS_POINTSIZE_MIN, d3d::FtoDw(0.0f));

	_device->SetRenderState(D3DRS_POINTSCALE_A, d3d::FtoDw(0.0f));
	_device->SetRenderState(D3DRS_POINTSCALE_B, d3d::FtoDw(0.0f));
	_device->SetRenderState(D3DRS_POINTSCALE_C, d3d::FtoDw(1.0f));

	_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
	_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

	_device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);

	_device->SetTexture(0, _point);
	_device->SetStreamSource(0, _vb, 0, sizeof(TerrainNode)); //this causes runtime error

	_device->DrawPrimitive( D3DPT_POINTLIST, 0, _numNodes );


	_device->SetRenderState(D3DRS_LIGHTING,          true);
	_device->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
	_device->SetRenderState(D3DRS_POINTSCALEENABLE,  false);
	_device->SetRenderState(D3DRS_ALPHABLENDENABLE,  false);

[edited by - Silex on January 18, 2004 4:46:43 PM]

Share this post

Link to post
Share on other sites
Sean Doherty    144

_device->SetStreamSource(0, _vb, 0, sizeof(TerrainNode)); //this causes runtime error

I would be willing to bet that the size of your vertex buffer is wrong and you area accessing memory that has not been defined. Can you post the code where you create the vertex buffer along with the data structure definitions?

Understanding is a three edged sword...

Have your independent game reviewed by your peers on the review ladder.

Share this post

Link to post
Share on other sites
Silex    140
This is where I fill and declare the buffer:

HRESULT hr = 0;
hr = _device->CreateVertexBuffer( _numNodes * sizeof(TerrainNode),
0 );

if ( FAILED(hr) )
return false;

// coordinates to start generating vertices at

int startX = -_width / 2 + _cellSpacing / 2;
int startZ = _depth / 2 - _cellSpacing / 2;

// coordinates to end generating vertices at

int endX = _width / 2 - _cellSpacing / 2;
int endZ = -_depth / 2 + _cellSpacing / 2;

TerrainNode* n;
_vb->Lock( 0, 0, (void**)&n, 0 );

int i = 0;
for(int z = startZ; z >= endZ; z -= _cellSpacing)
int j = 0;
for(int x = startX; x <= endX; x += _cellSpacing)
int index = i * _numCellsPerRow + j;

n[index] = TerrainNode(
getHeight(x, z),

j++; // next column

i++; // next row



And this is the TerrainNode definition:

struct TerrainNode
TerrainNode( float x, float y, float z, D3DCOLOR color )
_position.x = x; _position.y = y; _position.z = z; _color = color;
D3DXVECTOR3 _position;
D3DCOLOR _color;

static const DWORD FVF;

With the FVF defined as D3DFVF_XYZ | D3DFVF_DIFFUSE.

Share this post

Link to post
Share on other sites