Jump to content
  • Advertisement

Archived

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

Ruudje

Program crashing

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

Hey all. Im (still) working on a big 3d online project, but Ive run into some trouble. Each time I want to load a new world, I call a function to do so. This function reads in scripts from ini-files, and loads 3ds models. It then generates displaylists of those models. The problem is, the function only works once. during startup, I call the function, and the initial world is loaded just fine. If I call it again later to laod a new one however, the entire program freezes. Can anyone tell me why?
void TMainform::LoadWorldFromIni(AnsiString FileName)
{
        /*

                Load in the main world/map/scene or whatever

        */
        AnsiString CorrectedFileName = ".\\data\\" + FileName;

        TIniFile *ini;

        if(FileExists(FileName))
                ini = new TIniFile( FileName );
        else
                ini = new TIniFile( CorrectedFileName );

        // We need the following
        // - world id
        // - number of objects in it
        // - world mesh
        // - the id''s of the objects in the world

        // Read the ID
        world_id = ini->ReadInteger( "Wereld", "ID", 1 );

        // Number of objects
        num_objects = ini->ReadInteger( "Wereld", "Aantal", 0 );
        
        // World mesh
        AnsiString world_mesh = ini->ReadString( "Wereld", "Wereld", "");

        // Player startposition
        AnsiString player_start = ini->ReadString("Wereld", "Start", "0,0,0");

        char *x, *y, *z;

        x = strtok(player_start.c_str(), ",");
        y = strtok(NULL, ",");
        z = strtok(NULL, ",");

        Player[PlayerID].Position.x = StrToFloat(x);
        Player[PlayerID].Position.y = StrToFloat(y);
        Player[PlayerID].Position.z = StrToFloat(z);

        // If there is an old mesh present, delete it first
        if(World_model)
        {
                delete World_model;
                World_model = 0;
        }

        // Load the model
        if(FileExists(world_mesh))
        {
                World_model = new CModel;
                World_model->Load(world_mesh.c_str() );

                WorldDisplaylist = glGenLists(1);
                
                glNewList(WorldDisplaylist, GL_COMPILE);
                World_model->Render();
                glEndList();
        }

        // Load all objectscripts
        for(int i = 1; i <= num_objects; i++)
        {
                AnsiString scriptline = ini->ReadString( "Wereld", "Object"+IntToStr(i), 0 );

                // Pointers to substrings. The id is at 0
                char *x, *y, *z, *xrot, *yrot, *zrot, *targetworld, *url;

                // Decipher the scriptline
                strtok(scriptline.c_str(), ",");
                x = strtok(NULL, ",");
                y = strtok(NULL, ",");
                z = strtok(NULL, ",");
                xrot = strtok(NULL, ",");
                yrot = strtok(NULL, ",");
                zrot = strtok(NULL, ",");
                targetworld = strtok(NULL, ",");
                url = strtok(NULL, ",");

                // Now convert these substrings into useable values
                worldobject[i-1].id = StrToInt(scriptline) - 1;
                worldobject[i-1].Position.x = StrToInt(x);
                worldobject[i-1].Position.y = StrToInt(y);
                worldobject[i-1].Position.z = StrToInt(z);
                worldobject[i-1].Rotation.x = StrToInt(xrot);
                worldobject[i-1].Rotation.y = StrToInt(yrot);
                worldobject[i-1].Rotation.z = StrToInt(zrot);

                worldobject[i-1].Targetworld = String(targetworld);

                if(worldobject[i-1].Targetworld == "0")
                        worldobject[i-1].Targetworld = "";

                worldobject[i-1].Url = String(url);

                if(worldobject[i-1].Url == "0")
                        worldobject[i-1].Url = "";
        }

        delete ini;	
}
 
Is it possible that it is caused by me trying to create new a displaylist of the world, even though the old one still exists? any help would be greatly appreciated

Share this post


Link to post
Share on other sites
Advertisement
Where does your program crash?

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081

Share this post


Link to post
Share on other sites
The ide doesnt show it. The program just freezes as soon as I call that function. (the ide doesnt highlight any lines)

Share this post


Link to post
Share on other sites
Are you sure the ini file is complete? The rest seems ok to me.
Try loading the same world twice, look if it crashes then, if not, the 2nd ini file you tried to load isn't complete.

Or:

Try to set breakpoints.

[edited by - Living Monstrosity on December 16, 2003 6:37:47 AM]

Share this post


Link to post
Share on other sites
Is AnsiString a self-written class? Maybe there are some memory problems?

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081

Share this post


Link to post
Share on other sites
OR you can try not deleting everything you new.
I got access violation when deleting (or freeing when using malloc) is some of my functions for no clear reason at all, so i simply commented all delete blabla lines and now it workt fine, the memory is even deleted automatically when the pointer''s scope expires.

Share this post


Link to post
Share on other sites
quote:
Original post by Living Monstrosity
OR you can try not deleting everything you new.
I got access violation when deleting (or freeing when using malloc) is some of my functions for no clear reason at all, so i simply commented all delete blabla lines and now it workt fine, the memory is even deleted automatically when the pointer''s scope expires.


This is extremely bad! The memory is not deleted automatically in C or C++. There is an error in your code if the deletes give you access violations(i.e. your deleting memory that wasn''t allocated or double deleting it). The only time the memory MAY be freed is when the program closes completely. In newer systems this happens i.e. XP/2000 but older OS''s 9x don''t do this so you will be losing some memory until you reboot. You should try to find out why it is crashing instead - you ARE doing something wrong!

James

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!