fwrite crashes server
#1

I have a strange issue. I just got a new host (Linux). Everything works except my property saving function, which is:

pawn Код:
stock SaveProperties()
{
    new entry[256];
    new File: propfile = fopen("PropertySystem/PropertyInfo.txt", io_write);   
   
    for(new id; id<PropertiesAmount; id++)
    {  
        format(entry, sizeof(entry), "%s,%.2f,%.2f,%.2f,%d,%d,%s,%d,%d,%d \r\n",PropInfo[id][PropName], PropInfo[id][PropX], PropInfo[id][PropY], PropInfo[id][PropZ], PropInfo[id][PropValue], PropInfo[id][PropEarning], PropInfo[id][PropOwner], PropInfo[id][PropIsBought], PropInfo[id][PropUnbuyableTime], PropInfo[id][Type]);
        fwrite(propfile, entry);   
    }
    fclose(propfile);


}

And what is strange, on Windows (localhost) it works great. When I upload ALL property system regarded FILES to Linux server and use the function = server crash.

I also tried debugging:

pawn Код:
stock SaveProperties()
{
    print("P1");
    new entry[256];
    print("P2");
    new File: propfile = fopen("PropertySystem/PropertyInfo.txt", io_write);
    print("P3");
   
    for(new id; id<PropertiesAmount; id++)
    {
        print("P4");
        format(entry, sizeof(entry), "%s,%.2f,%.2f,%.2f,%d,%d,%s,%d,%d,%d \r\n",PropInfo[id][PropName], PropInfo[id][PropX], PropInfo[id][PropY], PropInfo[id][PropZ], PropInfo[id][PropValue], PropInfo[id][PropEarning], PropInfo[id][PropOwner], PropInfo[id][PropIsBought], PropInfo[id][PropUnbuyableTime], PropInfo[id][Type]);
        print("P5");
        fwrite(propfile, entry);
        print("P6");
    }
    fclose(propfile);
    print("P7");
}
Log output:

Код:
[12:28:21] P1
[12:28:21] P2
[12:28:21] P3
[12:28:21] P4
[12:28:21] P5
So fwrite crashes it.

Any solutions?

Regards
Reply
#2

pawn Код:
stock SaveProperties()
{
    print("P1");
    new entry[256];
    print("P2");
    new File: propfile = fopen("PropertySystem/PropertyInfo.txt", io_write);
    print("P3");
   
    for(new id; id<PropertiesAmount; id++)
    {
        print("P4");
        format(entry, sizeof(entry), "%s,%.2f,%.2f,%.2f,%d,%d,%s,%d,%d,%d \r\n",PropInfo[id][PropName], PropInfo[id][PropX], PropInfo[id][PropY], PropInfo[id][PropZ], PropInfo[id][PropValue], PropInfo[id][PropEarning], PropInfo[id][PropOwner], PropInfo[id][PropIsBought], PropInfo[id][PropUnbuyableTime], PropInfo[id][Type]);
        print("P5");
        fwrite(propfile, entry);
        print("P6");
        fclose(propfile);
        print("P7");
    }
    print("P8");
}
Try closing it inside the loop, might work
Reply
#3

Nevermind
Reply
#4

My friend (Jochemd, who just posted above) having problem when using fwrite on Linux. (Not anymore, my problem still exists)
Reply
#5

Try
pawn Код:
new File:propfile = fopen("PropertySystem/PropertyInfo.txt", io_write);
if(propfile)
{
    //If the file has been successfully created and/or opened
}
else
{
    //if the file had any issues to get opened. Mostly I use these lines to print an error message.
}
Reply
#6

This problem still exists. Anyone knows?
Reply
#7

I think the carriage return might cause the problem. This works okay on Windows, but it might not behave the same on Linux. Try with \n at the end of the line, instead of \r\n.
Reply
#8

Must try. Thanks


EDIT: No effect, need a solution quickly

This code makes problems now:

pawn Код:
stock SaveOrgs()
{
    new entry[156];
    new File: orgfile = fopen("orgs.txt", io_write);

    for(new id; id<OrgsAmount; id++)
    {
        format(entry, sizeof(entry), "%s,%d,%.2f,%.2f,%.2f,%s,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",Organization[id][OName], Organization[id][Skin], Organization[id][HQX], Organization[id][HQY],Organization[id][HQZ], Organization[id][Motto], Organization[id][Leader],
        Organization[id][EnableInt], Organization[id][Education],Organization[id][Weapons][0],Organization[id][Ammo][0],Organization[id][Weapons][1],Organization[id][Ammo][1],Organization[id][Weapons][2],Organization[id][Ammo][2],Organization[id][Weapons][3],Organization[id][Ammo][3],Organization[id][Weapons][4],Organization[id][Ammo][4], Organization[id][Money]);
        fwrite(orgfile, entry);
    }
    print("Orgs saved, too :)");

    fclose(orgfile);

}
But this is something I can't understand, IT WORKS ON WINDOWS BUT NOT ON LINUX?




EDIT: Found it out. Deleted the file and created all data again. Works now
Reply
#9

Make sure the directory exists, and note that Linux is cAsE sEnSiTiVe.
Reply
#10

Quote:
Originally Posted by MP2
Посмотреть сообщение
Make sure the directory exists, and note that Linux is cAsE sEnSiTiVe.
This. I'm pretty sure that it's the problem that you have.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)