SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 07/08/2017, 07:11 PM   #5641
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,724
Reputation: 1257
Default Re: Streamer Plugin

@Salik, @TommyB, @IstuntmanI - do not use strlen for non-strings under any circumstances! If you pass a brand new array, strlen will return 0 and I don't think it would do any harm, the maxlen param ends its life in this function: https://sourcegraph.com/github.com/s...oArray#L92-108 but it certainly wouldn't do anything useful at all.

Use sizeof, it's even the default. You can also limit the amount of work done by using some value lower than sizeof if for example you only want the closest 3 items.
[HLF]Southclaw is offline   Reply With Quote
Old 07/08/2017, 08:34 PM   #5642
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,880
Reputation: 366
Default Re: Streamer Plugin

Quote:
Originally Posted by [HLF]Southclaw View Post
@Salik, @TommyB, @IstuntmanI - do not use strlen for non-strings under any circumstances! If you pass a brand new array, strlen will return 0 and I don't think it would do any harm, the maxlen param ends its life in this function: https://sourcegraph.com/github.com/s...oArray#L92-108 but it certainly wouldn't do anything useful at all.

Use sizeof, it's even the default. You can also limit the amount of work done by using some value lower than sizeof if for example you only want the closest 3 items.
Well, I told him that it isn't recommended. I wrote something about sizeof too, but I deleted it afterwards, because that's not what he wants. sizeof only gets an array dimension size at compile time, but he wanted the number of IDs that will be filled in at run time (or maybe even more than that, if the array isn't big enough, maybe he wants the total nearby IDs without any array limit, which is what that function actually returns).

The downside of using strlen: it can report a wrong size if the whole array is filled up with IDs different than 0, so it won't find the internal 0 correctly. It may check too much causing some kind of buffer overflow.
__________________


IstuntmanI is online now   Reply With Quote
Old 07/08/2017, 08:43 PM   #5643
TommyB
Beta Tester
 
TommyB's Avatar
 
Join Date: Sep 2010
Location: Texas, USA.
Posts: 118
Reputation: 108
Default Re: Streamer Plugin

Quote:
Originally Posted by [HLF]Southclaw View Post
@Salik, @TommyB, @IstuntmanI - do not use strlen for non-strings under any circumstances! If you pass a brand new array, strlen will return 0 and I don't think it would do any harm, the maxlen param ends its life in this function: https://sourcegraph.com/github.com/s...oArray#L92-108 but it certainly wouldn't do anything useful at all.

Use sizeof, it's even the default. You can also limit the amount of work done by using some value lower than sizeof if for example you only want the closest 3 items.
That's strange because the following code works flawlessly for me.

PHP Code:
new DynamicPickup:pickups[300], Float:xFloat:yFloat:zidpickuparray[2];
GetPlayerPos(playeridxyz);
Streamer_GetNearbyItems(xyzSTREAMER_TYPE_PICKUPpickups300dist);
for(new 
0strlen(_:pickups); p++)
{
    
Streamer_GetArrayData(STREAMER_TYPE_PICKUPpickups[p], E_STREAMER_EXTRA_IDpickuparray);

    
//...

In fact, running that code in an area that only has two pickups gives me these results with strlen and sizeof.

Code:
[14:28:02] strlen: 2 sizeof: 300
The loop works exactly as intended and only iterates twice where I tested it. Using sizeof would in my case would would cause 300 iterations, 298 of them being absolutely useless.
__________________
TommyB is offline   Reply With Quote
Old 07/08/2017, 09:46 PM   #5644
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,724
Reputation: 1257
Default Re: Streamer Plugin

Just because something works doesn't mean it's a good thing to do!

The strlen use in your loop isn't good practice at all, the only reason it stops at the right value is because strings end with a zero cell but there's no guarantee that output array would be filled with zeroes after the given length (this is usually referred to as "undefined behaviour" - relying on this isn't ever a good idea as an implementation change in the plugin code could render your check code useless).

As mentioned before, the correct result size is actually returned as a value from the function, so the best way to handle this would be:

Code:
new DynamicPickup:pickups[300], Float:x, Float:y, Float:z, id, pickuparray[2], resultLength;
GetPlayerPos(playerid, x, y, z); 
resultLength = Streamer_GetNearbyItems(x, y, z, STREAMER_TYPE_PICKUP, pickups, sizeof(pickups), dist); 
for(new p = 0; p < length; p++) 
{ 
    Streamer_GetArrayData(STREAMER_TYPE_PICKUP, pickups[p], E_STREAMER_EXTRA_ID, pickuparray); 

    //... 
}
[HLF]Southclaw is offline   Reply With Quote
Old 10/08/2017, 01:03 AM   #5645
CodeStyle175
Huge Clucker
 
CodeStyle175's Avatar
 
Join Date: Apr 2014
Posts: 225
Reputation: 12
Default Re: Streamer Plugin

fixed your retard plugin
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
CodeStyle175 is offline   Reply With Quote
Old 10/08/2017, 02:51 AM   #5646
liguanhua123
Little Clucker
 
liguanhua123's Avatar
 
Join Date: Jun 2013
Location: China
Posts: 47
Reputation: 8
Default Re: Streamer Plugin

Well Done!Keep It!
__________________
liguanhua123 is offline   Reply With Quote
Old 10/08/2017, 06:57 PM   #5647
rt-2
Huge Clucker
 
rt-2's Avatar
 
Join Date: Jun 2011
Location: Montréal, Québec, Canada
Posts: 275
Reputation: 24
Default Re: Streamer Plugin

Quote:
Originally Posted by CodeStyle175 View Post
fixed your retard plugin
Get out of this forum if you cannot appreciate the best plugin on this entire forum..
You are a retarded noob with bad attitude and you will go nowhere in life.
rt-2
__________________
rt-2
My hardcore first person 1994 simulation in development:
SA Advance Roleplay
rt-2 is offline   Reply With Quote
Old 10/08/2017, 07:06 PM   #5648
kernel32
Little Clucker
 
kernel32's Avatar
 
Join Date: Sep 2016
Posts: 19
Reputation: 0
Default Re: Streamer Plugin

Quote:
Originally Posted by CodeStyle175 View Post
fixed your retard plugin
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
[sampgdk:warning] Index mismatch for OnPlayerStatsAndWeaponsUpdate (-10040 != -1003
The problem is not in this plugin
kernel32 is offline   Reply With Quote
Old 22/08/2017, 09:12 PM   #5649
BeckzyBoi
Beta Tester
 
Join Date: Dec 2006
Posts: 1,666
Reputation: 112
Default Re: Streamer Plugin

Any luck on finding the crash?
__________________
BeckzyBoi is online now   Reply With Quote
Old 22/08/2017, 09:38 PM   #5650
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,880
Reputation: 366
Default Re: Streamer Plugin

Quote:
Originally Posted by BeckzyBoi View Post
Any luck on finding the crash?
You can see the progress here: https://github.com/samp-incognito/sa...gin/issues/205 . Well, currently there's actually no progress.
__________________


IstuntmanI is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Checkpoint / Area sub-streamer for incognito's streamer plugin Pottus Includes 11 21/03/2014 07:31 PM
Need 3dtextlabel Streamer And Gangzone Streamer !! Please Help . Not streamer plugin . jame42 Scripting Help 4 30/05/2012 08:33 AM
Streamer plugin 0.3d rt-2 Plugin Development 7 05/12/2011 07:17 PM
Streamer Plugin Help! ColdXX Everything and Nothing 2 21/08/2010 11:28 PM
Streamer Plugin! ColdXX Help Archive 10 18/07/2010 01:47 PM


All times are GMT. The time now is 09:57 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.