Jump to content
  • Advertisement
Sign in to follow this  
Jemburula

Creating a Triangle Strip

This topic is 4490 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

Hello, I'm just trying to get a simple D3DPT_TRIANGLESTRIP happening. Here is my code
// Terrain.h
struct VertexXYZ
{
  float X, Y, Z;
};

class cTerrain
{
public:
  cTerrain();
  ~cTerrain(){Release();};

  void Init();
  void Release();
  void Render();
private:
  IDirect3DVertexBuffer9* VB;
};

// Terrain.cpp
void cTerrain::Init()
{
  VertexXYZ* Vertices;
  // *** Error occurs on line below: ***
  D3D->GetD3DDevice()->CreateVertexBuffer(6 * sizeof(VertexXYZ), D3DUSAGE_WRITEONLY, D3DFVF_XYZ, D3DPOOL_MANAGED, &this->VB, 0);

  VB->Lock(0, 0, (void**)&Vertices, 0);

  Vertices[0].X = 0.0f;
  Vertices[0].Y = 0.0f;
  Vertices[0].Z = 0.0f;
  
  // ... Snip ...

  Vertices[5].X = 6.0f;
  Vertices[5].Y = 3.0f;
  Vertices[5].Z = 0.0f;

  VB->Unlock();
  return;
};

void cTerrain::Render()
{
  D3D->GetD3DDevice()->SetStreamSource(0, VB, 0, sizeof(VertexXYZ));
  D3D->GetD3DDevice()->SetFVF(D3DFVF_XYZ);
  D3D->GetD3DDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 4);
  return;
};



I get an error at runtime: Unhandled exception at 0x4fe12059 in EtherealPlanes.exe: 0xC0000005: Access violation writing location 0x00000000. So from what I understand there is something wrong with VB pointing to 0, but I thought that was the point of CreateVertexBuffer(...), it was supposed to allocate the memory then make VB point to it? I don't understand. I am at a loss [sad] Could anyone help me out? Much appreciated, Jemburula

Share this post


Link to post
Share on other sites
Advertisement
"D3D->GetD3DDevice()" is that a pointer to an initialized IDirect3DDevice9 interface?

Share this post


Link to post
Share on other sites
Which pointer is NULL, is it D3D or VB?

Either way you have to check the documenation for the possible errors returned by each points creating function.

Dave

Share this post


Link to post
Share on other sites
Actually my mistake... it says "this" is null in the watch window. What the hell? How on earth does that work. Any ideas? Need me to post more code?

Share this post


Link to post
Share on other sites
Quote:
Original post by Jemburula
Actually my mistake... it says "this" is null in the watch window. What the hell? How on earth does that work.

A pointer with an invalid value (such as 0) doesn't necessarily immediately cause a crash. The crash happens when the pointer is actually used.
    cTerrain * terrain = 0;
terrain->Init();
This doesn't crash because calling a function doesn't actually dereference the pointer (even though it looks like it does). The crash will happen inside the function when this is dereferenced.

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!