Game Development Community

Vertex Buffer crashing

by Mike Kuklinski · in Torque Game Engine Advanced · 02/04/2005 (5:01 pm) · 1 replies

I am new to Vertex Buffers (and TSE), but I patched this together... but it crashes. The game will go black then crash.

I am [attempting] to modify James Lupiani's Star Rendering resource to work with TSE.

If anyone has any advice pertaining to the following code, please tell me:

bool Sky::loadStars()
{
   if(!GFXDevice::devicePresent() || mFirstLoad == 1) return 0;
   char path[1024], *p;
   dStrcpy(path, mStarListName);
   if((p = dStrrchr(path, '/')) != NULL) *p = 0;
   Stream *stream = ResourceManager->openStream(mStarListName);
   if(stream==NULL) return false;
   else
   {
      char buffer[512];
      U32 starCount;
      stream->readLine( (U8*)buffer, 512 );
      starCount = dAtoi( buffer );
      if(starCount > MAX_STARS) starCount = MAX_STARS;
      GFXVertexPC *Verts = new GFXVertexPC[starCount];
      ColorF col;
      for(int i=0; i<starCount; ++i)
      {
         if(stream->getStatus() == Stream::EOS) break;
         stream->readLine((U8*)buffer, 512);
         dSscanf( buffer, "%f\t%f\t%f\t%f\t%f\t%f\t%f", &Verts[i].point.x, &Verts[i].point.y, &Verts[i].point.z, &col.red, &col.green, &col.blue, &col.alpha );
         Verts[i].color = GFXVertexColor(col);
      }
      mStarsVB.set(GFX, starCount, GFXBufferTypeStatic);
      GFXVertexPC *vbVerts = mStarsVB.lock();
      dMemcpy( vbVerts, Verts, starCount * sizeof(GFXVertexPC) );
      mStarsVB.unlock();
      delete [] Verts;
      mNumStars = starCount;
   }
   ResourceManager->closeStream(stream);
   mFirstLoad = 1;
   return true;
}

Also, this is the definition of mStarsVB in the header:
GFXVertexBufferHandle<GFXVertexPC> mStarsVB;

#1
02/06/2005 (3:21 pm)
I don't see any error in the way you create the vertex buffers. Are you sure that it crashes in this method?