Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Data File Error(4.5)

This thread is locked; no one can reply to it. rss feed Print
Data File Error(4.5)
GibbSticks
Member #14,193
April 2012
avatar

hey all, allegro cc!
ive just joined the forums and must comment on this, when argv[0] is not the absolute path of my allegro game (in my case "F:\Allegro_Stuff\RTS2\bin\sws.bin") my datafile does not load correctly. I am starting my game module with a separate app with a menu and options and the like and its just starting the game with no user selected options just yet to see if it works. The calling app is written in C#, the game that its starting, and will eventually send the user selected options data to is written in C++. The calling app is using system("start bin\\sws.bin"); to start it.

So to the heart of my problem here; when the game is launched through the calling app argv[0] is shown to be bin\sws.bin and cause my datafile to not load. When I start the game through my IDE's execute command argv[0] is shown to be F:\Allegro_Stuff\RTS2\bin\sws.bin the datafile works fine. Any suggestions or is this just a limitation of allegro 4.5?

C++, C# developer

Hitler was a fan of Chaplin. Chaplin was therefore responsible for the murder of millions of lives.

Matthew Leverton
Supreme Loser
January 1999
avatar

What code are you using to load the data file? Specifically what path are you using, and are you compensating for the fact that the program can start up with any working directory by issuing a chdir(), etc?

raynebc
Member #11,908
May 2010

What we've done to counter this issue is to use get_executable_name() to change the current directory where appropriate (ie. before loading data within the application's folder).

Matthew Leverton
Supreme Loser
January 1999
avatar

GibbSticks
Member #14,193
April 2012
avatar

The code im using to load the datafile is:

inline void LoadGUI()
{
       gui_data = load_datafile("data/GUI.dat");
       if(gui_data == NULL)
       {
                   allegro_message("Could Not Load GUI.dat");
                   exit(EXIT_FAILURE);
       }
       _button = (BITMAP*)gui_data[0].dat;
       _buttonhighlight = (BITMAP*)gui_data[1].dat;
       gui_menu.CreateItem();
       return;
}

i do not understand the tehcnique that you linked to. Some explanation please?

the code the calling app is using is:

[DllImport("msvcrt.dll")]
    public static extern int system(String cmd);

//tonn of other stuff

system("start bin\\sws.bin");

C++, C# developer

Hitler was a fan of Chaplin. Chaplin was therefore responsible for the murder of millions of lives.

Matthew Leverton
Supreme Loser
January 1999
avatar

Assuming you have bin/data/GUI.dat:

#SelectExpand
1inline void LoadGUI() 2{ 3 char name[1024]; 4 get_executable_name(name, sizeof(name)); 5 replace_filename(name, name, "data/GUI.dat", sizeof(name)); 6 7 gui_data = load_datafile(name); 8 if(gui_data == NULL) 9 { 10 allegro_message("Could Not Load GUI.dat"); 11 exit(EXIT_FAILURE); 12 } 13 _button = (BITMAP*)gui_data[0].dat; 14 _buttonhighlight = (BITMAP*)gui_data[1].dat; 15 gui_menu.CreateItem(); 16 return; 17}

GibbSticks
Member #14,193
April 2012
avatar

thx for the speedy response Matthew, I copied and pasted the code you just posted however now the function is not even reporting that the data file is NULL, instead its just outright crashing 0.o

C++, C# developer

Hitler was a fan of Chaplin. Chaplin was therefore responsible for the murder of millions of lives.

Matthew Leverton
Supreme Loser
January 1999
avatar

You'll have to do some debugging. I'm not 100% sure that replace_filename works with folder + file.

GibbSticks
Member #14,193
April 2012
avatar

K Matthew, thanks anyway for your help. :)

C++, C# developer

Hitler was a fan of Chaplin. Chaplin was therefore responsible for the murder of millions of lives.

raynebc
Member #11,908
May 2010

replace_filename() does allow you to pass a "folder\filename" path, but I've never tried having it replace more than just the filename part.

Go to: