Thread: UGH! loading assimp indices into an an array of structures created with malloc.

  1. #1
    Registered User
    Join Date
    May 2014
    Posts
    15

    Question UGH! loading assimp indices into an an array of structures created with malloc.

    hi there. here are the relevant parts of my code. when i run the first part with the printfs found after every time i set a variable in the for loop they print the right values on the screen but when trying to print the values from the array where i stored the values i get garbage, 0's and numbers in the billions. I have spent a couple of hours on this. please help!!

    Code:
    struct aiMesh* mesh = scene->mMeshes[0];
        
        ObjectMesh->MeshIndexListSize = mesh->mNumFaces;
        
        ObjectMesh->MeshIndexList = (struct TypeVertexIndexList3  *)malloc(sizeof(struct TypeVertexIndexList3) * mesh->mNumFaces);
        
        for (int i = 0; i < mesh->mNumFaces; i++)
        {
            const struct aiFace* face = &mesh->mFaces[i];
            
            ObjectMesh->MeshIndexList[i].i0 = face->mIndices[0];
            printf("\n%u\n", face->mIndices[0]);
            ObjectMesh->MeshIndexList[i].i1 = face->mIndices[1];
            printf("\n%u\n", face->mIndices[1]);
            ObjectMesh->MeshIndexList[i].i2 = face->mIndices[2];
            printf("\n%u\n", face->mIndices[2]);
        }
    Code:
    typedef struct TypeVertexIndexList3
    {
        union
        {
            unsigned int indexlist[3];
            
            struct
            {
                unsigned int i0, i1, i2;
            };
        };    
    } IndexTriangle, VertexIndexList3;
    thanks again

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-17-2015, 05:50 PM
  2. malloc() with array of structures
    By khpuce in forum C Programming
    Replies: 8
    Last Post: 10-26-2010, 07:12 AM
  3. passing an array created with malloc as a param
    By mariano_donati in forum C Programming
    Replies: 12
    Last Post: 02-20-2008, 12:26 PM
  4. Array of indices
    By ronenk in forum C Programming
    Replies: 4
    Last Post: 06-15-2004, 05:36 PM
  5. malloc ing array's or structures
    By Markallen85 in forum C Programming
    Replies: 4
    Last Post: 02-03-2003, 01:23 PM