SA-MP Forums Archive
This function is crashing my server - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: This function is crashing my server (/showthread.php?tid=638754)



This function is crashing my server - Luke_James - 05.08.2017

Quote:

[16:41:17] [debug] AMX backtrace:
[16:41:17] [debug] #0 native fwrite () [004056e0] from samp-server.exe
[16:41:17] [debug] #1 000bdeb0 in ?? () from previousworkingtest.amx
[16:41:17] [debug] #2 0002f114 in ?? (0x00000017) from previousworkingtest.amx
[16:41:17] [debug] #3 00106348 in public dialog_ConfirmCarBuy (0x00000000, 0x00000001, 0xffffffff, 0x00820ef from previousworkingtest.amx
[16:41:17] [debug] #4 native CallLocalFunction () [004743b0] from samp-server.exe
[16:41:17] [debug] #5 0000c6bc in public OnDialogResponse (0x00000000, 0x00007fbc, 0x00000001, 0xffffffff, 0x00820ef4) from previousworkingtest.amx
[16:41:17] [debug] Native backtrace:
[16:41:17] [debug] #0 778aff33 in ?? () from C:\windows\SYSTEM32\ntdll.dll

PHP код:
Dialog:ConfirmCarBuy(playeridresponselistiteminputtext[])
{
    if (
response)
    {
        new
            
bizid Business_Inside(playerid),
            
carid PlayerData[playerid][pDealerCar],
            
price DealershipCars[bizid][carid][vehPrice];
        if (
bizid != -&& BusinessData[bizid][bizExists] && BusinessData[bizid][bizType] == 5)
        {
            if (
GetMoney(playerid) < price)
                return 
SendErrorMessage(playerid"You have insufficient funds for the purchase.");
            if (
Car_GetCount(playerid) >= MAX_OWNABLE_CARS)
                return 
SendErrorMessage(playerid"You already have %d vehicles (server limit)."MAX_OWNABLE_CARS);
            new 
id Car_Create(PlayerData[playerid][pID], DealershipCars[bizid][carid][vehModel], BusinessData[bizid][bizSpawn][0], BusinessData[bizid][bizSpawn][1], BusinessData[bizid][bizSpawn][2], BusinessData[bizid][bizSpawn][3], 11);
            if (
id != -1)
            {
                
Tax_AddPercent(price);
                
BusinessData[bizid][bizVault] += Tax_Percent(price);
                
Business_Save(bizid);
                
SendServerMessage(playerid"You have bought a %s for %s!"ReturnVehicleModelName(DealershipCars[bizid][carid][vehModel]), FormatNumber(price));
                
GiveMoney(playerid, -price);
                
ShowPlayerFooter(playerid"~w~Vehicle ~p~purchased!");
                
Log_Write("logs/car_log.txt""[%s] %s has purchased a %s for %s."ReturnDate(), ReturnName(playerid0), ReturnVehicleModelName(DealershipCars[bizid][carid][vehModel]), FormatNumber(price));
            }
        }
    }
    return 
1;

I'm completely stumped. The vehicle gets created in the database, but all the values are either blank or set to 0.


Re: This function is crashing my server - OneDay - 05.08.2017

use -d3 to get the line of the problem


Re: This function is crashing my server - Luke_James - 05.08.2017

Quote:

[00:39:02] [debug] Server crashed while executing finalscript.amx
[00:39:02] [debug] AMX backtrace:
[00:39:02] [debug] #0 native fwrite () [004056e0] from samp-server.exe
[00:39:02] [debug] #1 000fcc64 in Server_Save () at C:... \gamemodes\finalscript.pwn:17736
[00:39:02] [debug] #2 0003d23c in Tax_AddPercent (price=15) at C:.... \gamemodes\finalscript.pwn:4304
[00:39:02] [debug] #3 0015750c in public dialog_ConfirmCarBuy (playerid=0, response=1, listitem=-1, inputtext[]=@0x00828b34 "") at C:\Users\Luke\Desktop\Edgewood\gamemodes\finalscri pt.pwn:23198
[00:39:02] [debug] #4 native CallLocalFunction () [004743b0] from samp-server.exe
[00:39:02] [debug] #5 000102a4 in public OnDialogResponse (playerid=0, dialogid=32700, response=1, listitem=-1, inputtext[]=@0x00828b30 "") at C:... \pawno\include\easyDialog.inc:111
[00:39:02] [debug] Native backtrace:
[00:39:02] [debug] #0 77beff33 in ?? () from C:\windows\SYSTEM32\ntdll.dll

This is the output with debug level 3.

So where's it saying the cause of the crash is?


Re: This function is crashing my server - Misiur - 06.08.2017

Just look closely on the output.
Quote:

[00:39:02] [debug] #0 native fwrite () [004056e0] from samp-server.exe
[00:39:02] [debug] #1 000fcc64 in Server_Save () at C:... \gamemodes\finalscript.pwn:17736

finalscript.pwn at line 17736 calls fwrite. And probably the file handle is closed/invalid and that's why it is failing.


Re: This function is crashing my server - Luke_James - 06.08.2017

This is the line in question --

PHP код:
return (fwrite(filestr), fclose(file)); 
So it's trying to write to a file which doesn't exist?


Re: This function is crashing my server - Misiur - 06.08.2017

Show us this whole function. Probably it's something like
pawn Код:
new File:file = fopen("blah.txt", io_read),
 // (...)
return (fwrite(file, str), fclose(file));
while you should check the handle:
pawn Код:
new File:file = fopen("blah.txt", io_read),
if(!file) {
    return false; //or something
}
 // (...)
return (fwrite(file, str), fclose(file));



Re: This function is crashing my server - Luke_James - 06.08.2017

It turns out that it was trying to write to log files which weren't there, and the script didn't create the files either. The script now makes the files and I've also added your suggestion to prevent further crashes - fixed.