Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Red Drake

Mayor BUG detected

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

I am expirencing a wierd bug that I newer seen before. I am using Dev-Cpp v5 (beta) & mingw g++ 3.2 compiler. When I compile this code It runs yust fine until the main - "i" loop finishes.
void Model3D::LoadEEM(const char* FileName)
{
    // Variable

    FILE        *file;
    char        Header[10];
    int         i,j;    
    
    // Otvori fajl

    file = fopen(FileName, "rb");
    
    // Ocitaj i provjeri heder

    fread (Header,sizeof(char),10,file);
    if (strcmp (Header,"EEM001DGLA") == 0)
    {
        return;
    }    

    // Broj mesheva

    fread (&nMeshes, sizeof(int), 1, file);

    // Povećaj broj mesheva

    Meshes = new Mesh[nMeshes];
    
    // Provrti petlju kroz sve mesheve

    for (i = 0; i < nMeshes - 1; i++)
    {
        // Učitaj index za materijal

        fread (&Meshes[i].MaterialID, sizeof(int), 1, file);
        

        // Ocitaj broj vertexa

        fread (&Meshes[i].VertCount, sizeof(int), 1, file);
        
        // Povecaj aray za vertexe

        Meshes[i].Vertices = new Vertex [Meshes[i].VertCount];
        
        // Ucitaj vertexe kroz petlju

        for (j = 0; j < Meshes[i].VertCount; j++)
        {
            // Ucitaj poziciju vertexa

            fread(Meshes[i].Vertices[j].Position, sizeof(float),3, file);
            
            // Ucitaj tU & tV - texturine kordinate

            fread(&Meshes[i].Vertices[j].tU, sizeof(float),1, file);
            fread(&Meshes[i].Vertices[j].tV, sizeof(float),1, file);
            
            // Ucitaj index kosti

            Meshes[i].Vertices[j].BoneID = fgetc(file);
        }


        // Ucitaj broj normal vektora

        fread (&Meshes[i].NormalsCount,sizeof(int),1,file);
        
        // Povecaj aray za normal vektore

        Meshes[i].Normals = new Vector3[Meshes[i].NormalsCount];
        
        // Ucitaj normale kroz petlju

        for (j = 0; j < Meshes[i].NormalsCount; j++)
        {
            fread(Meshes[i].Normals[j], sizeof(float),3, file);
        }


        // Ucitaj broj trokuta

        fread (&Meshes[i].TriCount , sizeof(int), 1, file);
        
        // Povacaj aray za trokute

        Meshes[i].Triangles = new Triangle[Meshes[i].TriCount];

        // Ucitaj

        for (j = 0; j < Meshes[i].TriCount; j++)
        {
            // Ucitaj indexe vertexa

            fread(Meshes[i].Triangles[j].Indicates, sizeof(int),3, file);
            
            // Ucitaj indedxe normala

            fread(Meshes[i].Triangles[j].NormalInd, sizeof(int),3, file);
        }

    }


    // Ucitaj broj materjala

    fread (&nMaterials, sizeof(int), 1, file);
    
    Materials = new Material[nMaterials];
    
    for (i = 0; i < nMaterials; i++)
    {
        // Odnosi sa svjetlom 

        fread (Materials[i].Ambient,  sizeof(float), 4, file);
        fread (Materials[i].Diffuze,  sizeof(float), 4, file);
        fread (Materials[i].Specular, sizeof(float), 4, file);
        fread (Materials[i].Emissive, sizeof(float), 4, file);
    
        // Sjajnost & prozirnost

        fread (&Materials[i].Shines, sizeof(float), 1, file);
        fread (&Materials[i].Transparency, sizeof(float), 1, file);
    
        // Ime texture

        fread (Materials[i].TextureName, sizeof(char), 256, file);
    }



    // Ucitaj broj kosti 

    fread (&nBones, sizeof(int), 1, file);
    
    // Povecaj aray za kosti

    Bones = new Bone[nBones];
    
    // Ucitaj sve kosti

    for (i = 0; i < nBones; i++)
    {
        // Ucitaj pocetne kosti

        fread(Bones[i].Trans.Translation, sizeof(float),3,file);
        fread(Bones[i].Rotat.Rotation, sizeof(float),3,file);
        
        // Ucitaj broj translacijskih keyframova

        fread (&Bones[i].nKeyf_Translation, sizeof(int), 1, file);
        
        // Povećaj araj keyframeova za translaciju

        Bones[i].Keyf_Translation = new BoneKeyframe_Trans[Bones[i].nKeyf_Translation];
        
        // Prodi kroz sve keyframove za ovu kost

        for (j = 0; j < Bones[i].nKeyf_Translation; j++)
        {
           // Ucitaj translaciju i vrijeme 

           fread(Bones[i].Keyf_Translation[j].Translation , sizeof(float), 3, file);
           fread(&Bones[i].Keyf_Translation[j].Time, sizeof(float),1,file);         
        }

        // Ucitaj broj rotacijskih keyframova

        fread (&Bones[i].nKeyf_Rotation, sizeof(int), 1, file);
        
        // Povećaj araj keyframeova za translaciju

        Bones[i].Keyf_Rotation = new BoneKeyframe_Rotation[Bones[i].nKeyf_Translation];
        
        // Prodi kroz sve keyframove za ovu kost

        for (j = 0; j < Bones[i].nKeyf_Rotation; j++)
        {
           // Ucitaj translaciju i vrijeme 

           fread(Bones[i].Keyf_Rotation[j].Rotation , sizeof(float), 3, file);
           fread(&Bones[i].Keyf_Rotation[j].Time, sizeof(float),1,file);         
        }
    }
    
    fclose(file);
}
Note: Please ignore all the coments - they are in croatian and I don't hawe the time to remove them. I deebug trough all my app and it runs fine unstil the 'i' (the bracer befor "fclose(file);"- that line newer gets to run, I put a brake point on it and the code crashes befeore it gets to it) loop finishes when my program yust closes it self - I get no error mesages, no warnings by the debuger .... It yust crashes. So any idea why ?? P.S. This myght be a memory leak - yust a gues - buth i dno't know crap abouth them [edited by - Red Drake on June 6, 2004 5:46:55 PM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by downgraded
I can''t see where you declared and initialised nMaterials?



fread (&nMaterials, sizeof(int), 1, file);

Materials = new Material[nMaterials];


The dedclaration is in the class


// Vector3

typedef float Vector3 [3];

// Vector4

typedef float Vector4 [4];








//--------------------------------------------------------------------------------------------

//

// Model3D -> klassa za model 3D (animiran kostima). Model se učitava iz EEM formata.

//

// Red Drake

// (Rafael Munitić)

//--------------------------------------------------------------------------------------------

class Model3D
{
//----------------------------------------------------------------------------------------

// Strukture zs model

//----------------------------------------------------------------------------------------

public:

// Struktura vertexa

struct Vertex
{
Vector3 Position;
char BoneID;
float tU, tV;
};

// Struktura trokuta

struct Triangle
{
unsigned int Indicates[3];
unsigned int NormalInd[3];
};


// Strtuktura Mesha

struct Mesh
{
// Index za materijal

unsigned int MaterialID;

// Vertices buffer

Vertex* Vertices;
unsigned int VertCount;

// Triangles buffer

Triangle* Triangles;
unsigned int TriCount;

// Verticecs normals

Vector3* Normals;
unsigned int NormalsCount;
};


// Struktura materijala za mesh

struct Material
{
// Odnosi prema svijetlu za materijal

Vector4 Ambient, Diffuze, Specular, Emissive;

// Sjajnost i Prozirnost

float Shines, Transparency;

// Ime texture

char TextureName[256];
};


// Struktura Keyframe sa translacijom

struct BoneKeyframe_Trans
{
float Time;
Vector3 Translation;
};


// Struktura Keyframe sa rotacijom

struct BoneKeyframe_Rotation
{
float Time;
Vector3 Rotation;
};


// Struktura kosti

struct Bone
{
// Pozicija sada

BoneKeyframe_Trans Trans;
BoneKeyframe_Rotation Rotat;

// Rotacija i Translacija kosti

BoneKeyframe_Trans* Keyf_Translation;
unsigned int nKeyf_Translation;
BoneKeyframe_Rotation* Keyf_Rotation;
unsigned int nKeyf_Rotation;
};


//----------------------------------------------------------------------------------------

// Variable za model

//----------------------------------------------------------------------------------------

private:

// Meshevi

Mesh* Meshes;
unsigned int nMeshes;

// Materjali

Material* Materials;
unsigned int nMaterials;

// Kosti

Bone* Bones;
unsigned int nBones;



//----------------------------------------------------------------------------------------

// Funkcije za model

//----------------------------------------------------------------------------------------

public:

void LoadEEM (const char* FileName);
void Render (void);
void Update (float Time);
void Translate (void);


};


It''s probably not that kind of an error becouse it compiles OK - no errprs & warnings .

P.S.
That was fast

Share this post


Link to post
Share on other sites
I''d suggest you put some error checking in for the fread() calls, and perhaps some sanity checks for the size values that are read (e.g. check that nBones isn''t negative or stupidly big) to make sure that the file isn''t corrupt and messing things up.

Share this post


Link to post
Share on other sites
Already hawe ;(
For like a 1000 times.

I am teling you I even check the data and it''s OK. It''s somthing else probably.

P.S.
When the data is negative or somthing you will get an "Ilegal operation ..." or the "Blue screen of death"

Share this post


Link to post
Share on other sites
Well lok''s liek no response is coming in So I am about to rewrite the code (not the function buth the entire source file).
I think this coud be a compiler bug or somthing
I don''t know but I shure know that my code is not working.

Please if you hawe any solutions send them in so i don''t hawe to rewrite the code (I will do this next week becouse my school is preaty much at end & I hawe to pass some exames )

Share this post


Link to post
Share on other sites
Strcmp needs a null-terminated character array to work properly. Declare Header as char[11] and make sure it''s null-terminated before calling strcmp.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by exa_einstein
try another compiler (everybody has MsVC++ v6 ), it''ll show you if you really found a bug...


True I hawe it - but I hate it becouse it''s from Microsoft, it has ugly IDE and I don''t exactly hawe an "original" version

quote:

Strcmp needs a null-terminated character array to work properly. Declare Header as char[11] and make sure it''s null-terminated before calling strcmp.



Well this is why that strtcmp didn''t work but hawe you seen the code above it''s

if (strcmp (Header,"EEM001DGLA") == 0) // == 0 not != 0 becouse I din''t know the source of this buth still it crashes

{
return;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
char Header[11];

fread(/*... 10 bytes as before ...*/);
Header[10 /*11th byte*/] = 0; // This tells it where the end of the string is

if (strcmp(Header, "blahblah" == 0) then it matches

Share this post


Link to post
Share on other sites

  • 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!