Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8455415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:16:57+00:00 2026-06-10T12:16:57+00:00

im kinda stuck and i don’t know exactly where my problem might be. I

  • 0

im kinda stuck and i don’t know exactly where my problem might be. I am rendering a terrain divided by a quad tree. Now i am trying to make the boundaries of this quad tree visible for debugging purposes. Therefore im setting up a new buffer for each node on the terrain and only those debug quads wich are visible should be getting rendered. The problem i have is, that i am passing those node buffers to a method of another class (DebugTreeClass) by reference to create those there. But it seems like those buffers stay empty after the call of the method.
Here are my definitions:

1. m_debugTree->InitializeBuffer(node->vertexBufferDebug, node->indexBufferDebug, node->positionX, node->positionZ, node->width, device);

2. bool InitializeBuffer(ID3D11Buffer*,ID3D11Buffer*, float, float, float,ID3D11Device*);

And this is the method creating the index / vertex buffer:

bool DebugTreeClass::InitializeBuffer(ID3D11Buffer* vertexBuffer,ID3D11Buffer* indexBuffer, float positionX, float positionZ, float width, ID3D11Device* deviceContext){
VertexType* vertices;
unsigned long* indices;
int index, i, j;
D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
D3D11_SUBRESOURCE_DATA vertexData, indexData;
HRESULT result;

m_vertexCount = 8; // to form a quad with lines we need 24 points.

m_indexCount = 24;

// Create the vertex array.
vertices = new VertexType[m_vertexCount];
if(!vertices)
{
    return false;
}

// Create the index array.
indices = new unsigned long[m_indexCount];
if(!indices)
{
    return false;
}

//DEFINE THE 8 POINTS FOR THE QUAD
//UPPER LEFT
vertices[0].position = D3DXVECTOR3(positionX, width / 2, positionZ);
vertices[0].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
// UPPER RIGHT
vertices[1].position = D3DXVECTOR3(positionX + width, width / 2, positionZ);
vertices[1].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
// BOTTOM RIGHT
vertices[2].position = D3DXVECTOR3(positionX + width, -(width / 2), positionZ);
vertices[2].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
// BOTTOM LEFT
vertices[3].position = D3DXVECTOR3(positionX, -(width / 2), positionZ);
vertices[3].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
// UPPER LEFT BACKSIDE
vertices[4].position = D3DXVECTOR3(positionX, width / 2, positionZ + width);
vertices[4].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
// UPPER RIGHT BACKSIDE
vertices[5].position = D3DXVECTOR3(positionX + width, width / 2, positionZ + width);
vertices[5].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
// BOTTOM RIGHT BACKSIDE
vertices[6].position = D3DXVECTOR3(positionX + width, -(width / 2), positionZ + width);
vertices[6].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
// BOTTOM LEFT BACKSIDE
vertices[7].position = D3DXVECTOR3(positionX, -(width / 2), positionZ + width);
vertices[7].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);

//SET UP THE INDEXBUFFER
indices[0] = 0;
indices[1] = 1;
indices[2] = 1;
indices[3] = 2;
indices[4] = 2;
indices[5] = 3;
indices[6] = 3;
indices[7] = 0;
indices[8] = 0;
indices[9] = 4;
indices[10] = 1;
indices[11] = 5;
indices[12] = 2;
indices[13] = 6;
indices[14] = 3;
indices[15] = 7;
indices[16] = 4;
indices[17] = 5;
indices[18] = 5;
indices[19] = 6;
indices[20] = 6;
indices[21] = 7;
indices[22] = 7;
indices[23] = 4;

// Set up the description of the static vertex buffer.
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
vertexBufferDesc.StructureByteStride = 0;

// Give the subresource structure a pointer to the vertex data.
vertexData.pSysMem = vertices;
vertexData.SysMemPitch = 0;
vertexData.SysMemSlicePitch = 0;

// Now create the vertex buffer.
result = deviceContext->CreateBuffer(&vertexBufferDesc, &vertexData, &vertexBuffer);
if(FAILED(result))
{
    return false;
}

// Set up the description of the static index buffer.
indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;
indexBufferDesc.StructureByteStride = 0;

// Give the subresource structure a pointer to the index data.
indexData.pSysMem = indices;
indexData.SysMemPitch = 0;
indexData.SysMemSlicePitch = 0;

// Create the index buffer.
result = deviceContext->CreateBuffer(&indexBufferDesc, &indexData, &indexBuffer);
if(FAILED(result))
{
    return false;
}

// Release the arrays now that the buffers have been created and loaded.
delete [] vertices;
vertices = 0;

delete [] indices;
indices = 0;

return true;

}

There are 2 classes, the “QuadTreeClass” where the nodes get defined and the “DebugTreeClass” where the buffers for each node should get filled and the rendering of the debug quads take place.
If im debugging the “DebugTreeClass::InitializeBuffer()” method i can see that the buffers should get created successfully, so im pretty sure that something is wrong with the passing by reference to this method. Maybe im just blind….

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:16:59+00:00Added an answer on June 10, 2026 at 12:16 pm

    I’m pretty sure the problem is here:

    bool DebugTreeClass::InitializeBuffer(ID3D11Buffer* vertexBuffer,...
    ...
    result = deviceContext->CreateBuffer(&vertexBufferDesc, &vertexData, &vertexBuffer)
    

    You are probably expecting the vertexBuffer to arrive in the caller of “InitializeBuffer”, but that doesn’t happen. You are talking about references, but you are not actually passing a reference. This will probably fix it:

    bool DebugTreeClass::InitializeBuffer(ID3D11Buffer*& vertexBuffer,...
    

    Same for the other pointers that you want to return.

    Your original version copied the old (probably uninitialized — you should enable warnings) pointer variable from the caller into the “vertexBuffer” variable of the function, and used that. “vertexBuffer” was a local variable for the function, it never got passed back.

    With my change, it is turned into a “reference to a pointer”. Now, the “vertexBuffer” pointer is actually the same pointer as the one passed into the function call, using the same memory. So, when you change that pointer, the version in caller is changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm kinda stuck on something... I'm trying to get #right to be the same
I'm kinda stuck with something which must be appalingly simple. I'm trying to write
i'm trying to get an OAuth server working but i'm kinda stuck a bit
I'm kinda stuck trying to see why, when I use this custom UIView to
Kinda stuck here... I have an application with lets say 5000 rows of data
I'm kinda stuck on this decision. My project already uses Spring and Spring Blazeds
I've attached a source file below, I'm kinda stuck. Basically, its an FLA that
I'am just playing around with CA lately. Now I am kind of stuck. This
I usually don't need to ask Java questions, but I'm stuck more than ever
I was trying to make a board game in java and i am stuck

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.