Memory leak? - 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: Memory leak? (
/showthread.php?tid=649902)
Memory leak? -
GaByM - 17.02.2018
Is there any problems if I do this?
PHP код:
main()
{
CallLocalFunction("func", "iii", val1, val2, val3);
// or SetTimerEx("func", 5, false);
}
#include <YSI\y_hooks>
hook func(val1)
{
// I do not need val2 and val3 here, so there is just val1 as parameter
//etc..
return 1;
}
I know it works and it compiles, but can this cause memory leaks / other problems?
Re: Memory leak? -
Mugala - 17.02.2018
in calling local func u're using3 params, instead of 1 params, or increase params in func()
also if u use SetTimerEx, u need to use params as well
Re: Memory leak? -
GaByM - 17.02.2018
Well, i know i have 3 arguments and then 1. That's what I ask: can be dangerous if I call a function with more parameters than the public?
Why? look:
PHP код:
SpawnCar(type, Float:x, Float:y, Float:z, Float:a, c1, c2, respawn=300, addsiren=0)
{
new id = CreateVehicle(type, x, y, z, a, c1, c2, respawn, addsiren);
if(id != INVALID_VEHICLE_ID)
CallLocalFunction("OnVehicleCreate", "iiffffiiii", q, type, x, y, z, a, c1, c2, respawn, addsiren);
return id;
}
// inside vehicle_data.inc
#include <YSI\y_hooks>
hook OnVehicleCreate(vehicleid)
{
Vehicle_Fuel[vehicleid] = 0;
Players_In_Vehicle[vehicleid] = 0;
// i don't need info about vehicle's spawn pos here, so there is just vehicleid as parameter.
}
// inside vehicle_mod_and_colors.inc
#include <YSI\y_hooks>
hook OnVehicleCreate(vehicleid, type, Float:x, Float:y, Float:z, Float:a, c1, c2)
{
Vehicle_Color_1[vehicleid] = c1;
Vehicle_Color_2[vehicleid] = c2;
// here I need details about colors.
}
Re: Memory leak? -
OneDay - 17.02.2018
Yes the code is good.
Re: Memory leak? -
Dayrion - 17.02.2018
You can not call a public function and passing some parameters. Public can not have default parameters and make you pass them. Hooking a function is calling this function. When you use a function, you need to provide every obligatory parameters.