Jump to content
  • Advertisement
Sign in to follow this  

SOLVED: City Frustum Culling (Multiple Index Buffers?)

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

If you intended to correct an error in the post then please contact us.

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));


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.


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

Share this post

Link to post
Share on other sites
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 this post

Link to post
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!