Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

zOMG SegFault

Name: Anonymous 2007-01-19 23:53

Teh Problem:  I'm trying to read a binary 3d file format.  The member variable types object_data, vertex, normal, and poly are structures that match with what is described in the file spec. I've looked at the hex directly, and it looks like the addresses line up, so I think I can pull off this read operation. But as soon as I try to use any of the dynamic arrays (by outputting to  another file), i get a seg fault/access violation. I pray to the /prog/ gods for guidance!


Teh class:

class PolyObject
{
  public:
   PolyObject ();                       // blank constructor
   PolyObject (ifstream& geoFile, int address);       // read constructor
   PolyObject (const PolyObject& source);             // copy constructor
   ~PolyObject ();                                    // destructor
   void write_obj (ofstream& jout, int& lastV, int& lastVT);
                                                      // write

  private:
   object_data POtag;                  // has format per .geo file spec
   char    *pName;                     // name of polygon object
   int      lenName;
   vertex  *pVertexList;               // vertex dynamic array
   normal  *pNormalList;               // normal dynamic array
   poly    *pPolyList;                 // poly dynamic array
   int      totalNormals;              // face normals + vertex normals
};

Teh Construxxor:

PolyObject::PolyObject (ifstream& geoFile, int address)
{
   geoFile.seekg(address);
   geoFile.read((char*)&POtag, SIZE_OBJECT_ENTRY);
   totalNormals = POtag.nVertexNormals + POtag.nFaceNormals;
   lenName = getStringLength(geoFile, POtag.oName);

   pName       = new char[lenName];       // should be null-terminated ok
   pVertexList = new vertex[POtag.nVertices];
   pNormalList = new normal[totalNormals];
   pPolyList   = new poly[POtag.nPolys];

   geoFile.seekg(POtag.oName);            // read in name
   geoFile.read(pName, lenName);

   geoFile.seekg(POtag.oVertexList);      // read in vertices (however many)
   geoFile.read((char*)pVertexList, POtag.nVertices * SIZE_VERTEX_ENTRY);

   geoFile.seekg(POtag.oNormalList);      // read in normals (however many)
   geoFile.read((char*)pNormalList, totalNormals * SIZE_NORMAL_ENTRY);

   geoFile.seekg(POtag.oPolyList);        // read in polys
   geoFile.read((char*)pPolyList, POtag.nPolys * SIZE_POLY_ENTRY);
}

Name: Anonymous 2007-01-20 5:14

>> PolyObject (ifstream& geoFile, int address);       // read constructor

NO!!! do this instead:
friend ifstream& operator>>(ifstream& is, PolyObject& p) {
    ...
    return is;
}


>> void write_obj (ofstream& jout, int& lastV, int& lastVT

NO!!! Once again, you're a moron, do this instead:
ostream& operator<<(ostream& os, const PolyObject& p) // ...

Name: Anonymous 2009-01-14 13:07

LISP

Name: Anonymous 2010-12-06 9:52

Back to /b/, ``GNAA Faggot''

Name: Sgt.Kabu咕kiman䐂᧵ 2012-05-28 22:08

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List