Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] Long callback execution

 
  • 0 Vote(s) - 0 Average
Pawn Long callback execution
Snow
Offline

Burgershot Member
Posts: 48
Threads: 5
Joined: Oct 2020
Reputation: 2
Location: Pakistan
#1
2021-05-02, 02:10 AM (This post was last modified: 2021-05-02, 02:10 AM by Snow.)
I am getting tons of long callback executions in my server logs, People told me the that I need to shorten my functions and optimize the code. This is one of the functions that also detects long callback execution. So I'm gonna need an example from this to fix the long execution. Hoping to get some help here. 

Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
        InCar[playerid] = 0;
        LastCar[playerid] = vehicleid;

        if(DeliveryMan[playerid])
        {
            for(new i; i<sizeof(BurritoSpawnInfo); i++)
            {
                if(GetPlayerVehicleID(playerid) == Burrito_ID[i])
                {
                    SendClientMessage(playerid, COLOR_COURIER, "* Press Y behind your vehicle to pickup the goods.");   
                }   
            }
           
        }
        return 1;
}
[Image: QIDa2vB.png]
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#2
2021-05-02, 07:29 PM
Well the question there is, how many burrito vans do you have? However, the long callback is the whole callback, so do you have any other hooks of that callback?
kemper
Offline

Burgershot Member
Posts: 6
Threads: 0
Joined: Dec 2020
Reputation: 0
Location: Kyiv, Ukraine
#3
2021-05-02, 07:37 PM
I wouldn't call this code terrible or something. But there is a logical error.
If you have met the condition you need, then break out of the loop.
Also you already know vehicleid so you don't need to call GetPlayerVehicleID every time.

Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
        InCar[playerid] = 0;
        LastCar[playerid] = vehicleid;

        if(DeliveryMan[playerid])
        {
            for(new i; i < sizeof(Burrito_ID); i++)
            {
                if(vehicleid == Burrito_ID[i])
                {
                    SendClientMessage(playerid, COLOR_COURIER, "* Press Y behind your vehicle to pickup the goods.");
break;
                } 
            }
         
        }

        return 1;
}
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#4
2021-05-02, 11:32 PM
No, that code isn't terrible at all. It is correct that there are a few minor improvements that could be made, but I didn't even bother mentioning them because they are no where near significant enough to trigger the slow code warning. That's why I asked about other hooks of the same callback, ones that might have far more code in. Alternatively, could you post the exact error from the console?
Snow
Offline

Burgershot Member
Posts: 48
Threads: 5
Joined: Oct 2020
Reputation: 2
Location: Pakistan
#5
2021-05-03, 03:35 AM (This post was last modified: 2021-05-03, 03:52 AM by Snow.)
So here's something weird happening. I tried commenting the whole callback to see if it still happens and yeah, I'm still getting the warning in the console. I've checked all the includes manually to look for OnPlayerExitVehicle (except for ysi includes and mysql) and didn't find any hooks. Here's the direct code from the console
Code:
[debug] Long callback execution detected (hang or performance issue)
[debug] AMX backtrace:
[debug] #0 00003418 in ?? (0, 121, 51966748, 1598650688) in uhf.amx
[debug] #1 00003644 in ?? (0, 0, 51966780, 1598650688) in uhf.amx
[debug] #2 00004b8c in ?? () in uhf.amx
[debug] #3 00001c58 in public OnPlayerExitVehicle () in uhf.amx
[Image: QIDa2vB.png]
AbyssMorgan
Offline

Burgershot Member
Posts: 63
Threads: 25
Joined: Apr 2021
Reputation: 8
Location: Poland
#6
2021-05-03, 06:37 AM
When you create Burrito vehicles add flag for burito vehicle and store burito id if you need
Code:
for(new i; i < sizeof(Burrito_ID); i++)
{
    some_vehicle_global_var[Burrito_ID[i]]][isBurito] = true;
    some_vehicle_global_var[Burrito_ID[i]]][BuritoID] = i;
}

Then you dont need loop
Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
        InCar[playerid] = 0;
        LastCar[playerid] = vehicleid;

        if(DeliveryMan[playerid])
        {
            if(some_vehicle_global_var[vehicleid][isBurito]){
                SendClientMessage(playerid, COLOR_COURIER, "* Press Y behind your vehicle to pickup the goods.");
            }
        }

        return 1;
}
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#7
2021-05-03, 01:19 PM
I still really don't think the problem is there. None of those calls even look like the code in your callback. But the best way to know is to recompile with `-d3`, which will allow the error message to display the full function names.
Snow
Offline

Burgershot Member
Posts: 48
Threads: 5
Joined: Oct 2020
Reputation: 2
Location: Pakistan
#8
2021-05-03, 03:03 PM
Hi. This is what I got with d3 enabled.
Code:
[debug] Long callback execution detected (hang or performance issue)
[debug] AMX backtrace:
[debug] #0 00003930 in AMX_GetEntryPrefix (E_AMX_TABLE:table=0, idx=82, &[email protected] 0, pattern=1598650688) at C:\***\server\pawno\include\YSI_Data\y_foreach\..\..\YSI_Core\y_core\y_amx_impl.inc:465
[debug] #1 00003d04 in AMX_GetPointerPrefix (E_AMX_TABLE:table=0, idx=0, &[email protected] 0, pattern=1598650688) at C:\***\server\pawno\include\YSI_Data\y_foreach\..\..\YSI_Core\y_core\y_amx_impl.inc:728
[debug] #2 00005644 in ScriptInit_PreInitFuncs_ () at C:\***\server\pawno\include\YSI_Data\y_foreach\..\..\YSI_Core\y_core\y_core_entry.inc:173
[debug] #3 00001e50 in public OnPlayerExitVehicle () at C:\***\server\pawno\include\YSI_Data\y_foreach\..\..\YSI_Core\y_core\y_scriptinit_impl.inc:629
I believe this has to do something with the ysi includes or the amx assembly?
[Image: QIDa2vB.png]
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#9
2021-05-03, 03:48 PM
OK, I'm not sure why but the main callback is being misreported. The good news is that this is therefore an init function and you don't need to worry about it. Try update YSI anyway, as the later versions should disable that warning in `OnScriptInit`.
Snow
Offline

Burgershot Member
Posts: 48
Threads: 5
Joined: Oct 2020
Reputation: 2
Location: Pakistan
#10
2021-05-03, 05:39 PM
(2021-05-03, 03:48 PM)Y_Less Wrote: OK, I'm not sure why but the main callback is being misreported.  The good news is that this is therefore an init function and you don't need to worry about it.  Try update YSI anyway, as the later versions should disable that warning in `OnScriptInit`.

Weird, because I am already using the latest YSI includes from the github.
[Image: QIDa2vB.png]
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode