SOLVED: City Frustum Culling (Multiple Index Buffers?)

This topic is 2598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi everyone.

Basically I'm trying to implement frustum culling for a city I have created in DirectX.

The city is generated using a 2D array. I randomly choose positions for the buildings. These buildings are constructed and then added to one vertex buffer.

I've divided my 2D array into subgrids. These subgrids each have an AABB and their own index buffer, storing data on the buildings within that area.

The world has a list of subgrids and when iterating through in the Render code of my application. The idea is to check if the frustum collides with the subgrid's AABB and if it does, draw the contents of current index buffer.

However at the moment when I iterate through each subgrid and attempt to draw using the index buffer, when it gets to the second element within the for loop it gives me the following error:

Unhandled exception at 0x692b793c in City.exe 0xC0000005: Access violation reading location 0x0000000c.

But the 1st subgrid operates fine and I create the content in the subgrid in other subgrids the same. The content in the Render function is:

int buildingCount = 0;	for (int i = 0; i < m_pSubGrids.size(); i++)	{		buildingCount = m_pSubGrids->count;		HR(gd3dDevice->SetIndices(&m_pSubGrids->IB)); // Crashes here		HR(gd3dDevice->SetTransform(D3DTS_WORLD, &m_pCamera->GetWorldMatrix()));		HR(gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW));		HR(gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID));		HR(gd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT));		HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24 * buildingCount, 0, 12 * buildingCount));		m_pSubGrids->AABB->Render(m_pCamera->GetWorldMatrix());	}

I'm probably doing something silly (as per usual), but I'm trying to figure out the cause of the problem at the moment.

Also, if anyone has any good ideas on how to structure the city fro frustum culling please give your suggestion.

Cheers.

[Edited by - Tumain on December 11, 2010 10:51:51 AM]

Share on other sites
&m_pSubGrids->IB
I don't quite get the rationale of this. Shouldn't you use two different indices for first?
Suppose m_pSubGrids.size() evaluates to 130. If m_pSubGrids[100] counts 50 index buffers, isn't that going to tear itself apart?
Does the above make sense for your system (maybe the IB array is shared between all objects, I don't know)?
I mean, if the IB array belongs to m_pSubGrids, I'd expect some kind of partitioning to have been already performed. Would you elaborate on your layout?

Why are you setting up multiple IBs? Do you really need it? Also, why setting CULLMODE, SHADEMODE and FILLMODE in a loop? If this is required by m_pSubGrids->AABB->Render(m_pCamera->GetWorldMatrix()); you might consider moving this detail in the function instead.

Share on other sites
Thanks Krohm. I guess all I needed was a fresh pair of eyes. I have no idea at all why I was doing that.

The multiple index buffers are just used for each subgrid, so in the render code I can decide which should be drawn and which one shouldn't.