Raised This Month: $12 Target: $400
 3% 

[BUG - RESOLVED] Infinite loop EngFunc_FindEntityInSphere for some maps


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hebusletroll
Senior Member
Join Date: Apr 2006
Old 09-20-2008 , 11:13   [BUG - RESOLVED] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #1

Hi Friends,

Since some days i've noticed a bug by using Find Entity In Sphere method that work fine on "basics" maps (that contain few entities), but make an infinite loop for maps like de_torn, de_airstrip, cs_manoir, etc.

After logging entity list, it appears that same entities are processed, when the count is over 32 entities in the sphere.

The loop will appears when the radius reach a certain ammount (approximatively 700.0 for de_airstrip).

Please note that the loop appears too when using engine method !!!!

I will provide my plugin test (use "dotest" command to spawn a entity) : when the entity is touching certains obstacle, the game is freezed.

Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

#define PLUGIN "TryIt"
#define VERSION "1.0"
#define AUTHOR "Hebusletroll"

#define modeltype "models/boid.mdl"

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_clcmd("dotest","cmd_dotest")
	register_forward(FM_Touch,"try_touch")
}

public plugin_precache()
{
	precache_model(modeltype)
}

public cmd_dotest(id)
{
	static Float:origin[3],Float:velocity[3],Float:angles[3]
	if(is_user_alive(id))
	{
		new entity = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
		if(entity)
		{
			pev(id,pev_origin,origin)
			pev(id,pev_angles,angles)
			velocity_by_aim(id,750,velocity)
			set_pev(entity,pev_classname,"try")
			set_pev(entity,pev_model,modeltype)
			engfunc(EngFunc_SetModel, entity, modeltype)
			set_pev(entity,pev_velocity,velocity)
			set_pev(entity,pev_solid,SOLID_BBOX)
			set_pev(entity,pev_movetype,MOVETYPE_FLY)
			set_pev(entity,pev_owner,id)
			set_pev(entity,pev_origin,origin)
			set_pev(entity,pev_angles,angles)
		}
	}
	return FMRES_HANDLED
}

public try_touch(ptr,ptd)
{
	static ptrClassName[64],Float:origin[3],victim
	if(ptd!=pev(ptr,pev_owner))
	{
		pev(ptr,pev_classname,ptrClassName,sizeof(ptrClassName))
		if(equali(ptrClassName,"try"))
		{
			victim = -1
			pev(ptr,pev_origin,origin)
			while((victim=engfunc(EngFunc_FindEntityInSphere,victim,origin,700.0))!=0)
			{
				client_print(pev(ptr,pev_owner),print_chat,"Entity ID = %d",victim)
			}
			engfunc(EngFunc_RemoveEntity,ptr)
		}
	}
}
Here, you can find some screenshots where the game will freeze.





Any body has find an issue ?

Best regards.
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x

Last edited by hebusletroll; 09-20-2008 at 12:08.
hebusletroll is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-20-2008 , 11:20   Re: [BUG ???] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #2

Shouldn't you remove the entity inside of the while loop ??
Else, there is no reason to do a loop, just do victim = enfgunc...

-edit-
I may have read too fast
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 09-20-2008 at 11:23.
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-20-2008 , 11:27   Re: [BUG ???] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #3

Touch is called very often per second, while you do a tracesphere among all entities each time. Maybe should you try to delay a bit.
__________________
Arkshine is offline
hebusletroll
Senior Member
Join Date: Apr 2006
Old 09-20-2008 , 11:40   Re: [BUG ???] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #4

Hello Arkshine,

Touch is a CallBack event function, and the sphere detection is only called once (because toucher entity is removed after processing). So i ununderstand how it is possible that the touche is called back again if no entity that has "try" classname exists.

When reducing the radius, the freeze disappears
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x
hebusletroll is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-20-2008 , 12:08   Re: [BUG ???] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #5

Just tried with a radius of 1000 on de_airstrip... No problem at all. ( I've modified a bit your code ).

Is there a specific way to do the test ? Or just when I spawn, I do the command in random angle, is fine ?
__________________
Arkshine is offline
hebusletroll
Senior Member
Join Date: Apr 2006
Old 09-20-2008 , 12:10   Re: [BUG - RESOLVED] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #6

It crash where the screenshot was made.

OK i will fix it by creating a Stock :

Code:
stock get_entities_near_origin(Float:origin[3],entitylist[],Float:radius)
{
	new entitycount, index, entityid
	while((entityid=engfunc(EngFunc_FindEntityInSphere,entityid,origin,radius))!=0)
	{
		for(index=0;index<entitycount;index++)
			if(entityid==entitylist[index])
				return entitycount
		entitylist[entitycount]=entityid
		entitycount+=1
	}
	return entitycount
}
You just need to create an array and use the stock like this :

Code:
new entitylist[512], victim
for(victim=0;victim<get_entities_near_origin(origin,entitylist,700.0);victim++)
{
    // Make your code here !
}
Now, it's work fine ! No more bug !

Yeah !
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x

Last edited by hebusletroll; 09-20-2008 at 12:13. Reason: Updated code
hebusletroll is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-20-2008 , 12:30   Re: [BUG - RESOLVED] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #7

Really, I don't understand your problem lol.

With this code ( radius 2000 / 139 entities found ) :

Code:
public Forward_Touch ( const i_Ent, const i_Other ) {     if ( pev_valid ( i_Ent ) && pev ( i_Ent, pev_iuser1 ) && i_Other != pev ( i_Ent, pev_owner ) )     {         static Float:vf_Origin[ 3 ], i_Victim;         pev ( i_Ent, pev_origin, vf_Origin ); i_Victim = -1;                 while ( ( i_Victim = engfunc ( EngFunc_FindEntityInSphere, i_Victim, vf_Origin, 2000.0 ) ) )         {             log_amx ( "Entity ID = %d", i_Victim );         }                 set_pev ( i_Ent, pev_flags, FL_KILLME );     } }

It returns, when I do the command at the terrorist spawn :

Code:
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 2
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 3
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 5
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 39
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 40
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 53
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 54
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 57
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 58
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 66
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 67
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 70
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 71
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 79
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 80
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 81
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 132
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 155
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 156
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 157
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 158
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 159
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 160
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 161
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 162
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 163
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 164
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 165
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 166
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 167
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 168
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 169
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 170
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 176
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 177
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 178
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 179
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 180
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 181
L 09/20/2008 - 18:26:36: [Untitled.amxx] Entity ID = 182
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 183
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 184
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 185
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 186
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 187
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 188
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 196
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 263
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 264
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 265
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 266
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 272
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 273
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 274
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 282
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 283
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 284
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 288
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 289
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 290
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 291
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 292
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 293
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 294
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 295
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 296
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 297
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 298
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 299
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 300
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 301
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 302
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 303
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 316
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 336
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 337
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 338
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 339
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 340
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 341
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 342
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 343
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 344
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 345
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 346
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 347
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 348
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 349
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 350
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 351
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 352
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 353
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 354
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 355
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 356
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 357
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 358
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 359
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 360
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 361
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 362
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 363
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 364
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 365
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 366
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 367
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 368
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 369
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 370
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 371
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 372
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 373
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 375
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 376
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 385
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 386
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 388
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 392
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 394
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 397
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 399
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 400
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 401
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 413
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 414
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 418
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 423
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 429
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 431
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 432
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 433
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 434
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 435
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 437
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 442
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 443
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 444
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 445
L 09/20/2008 - 18:26:37: [Untitled.amxx] Entity ID = 446
And as you can see, there are not same entities. In game, no crash at all. Probably something I did not understand in your message.
__________________
Arkshine is offline
solidsnake
Member
Join Date: Jul 2006
Old 09-20-2008 , 12:47   Re: [BUG - RESOLVED] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #8

I've tested your plugin, crashing on de_airstrip, de_torn, de_piranesi and de_tides.

With your stock, it work fine ! GG !
solidsnake is offline
hebusletroll
Senior Member
Join Date: Apr 2006
Old 09-20-2008 , 12:47   Re: [BUG - RESOLVED] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #9

Arkshine,

Please read the post again !

I've mentionned that the game crash when you firing where the SCREENSHOTS are displayed .

And i've find a members that have already the problem :
http://forums.alliedmods.net/showthr...=sphere+radius
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x
hebusletroll is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-20-2008 , 12:58   Re: [BUG - RESOLVED] Infinite loop EngFunc_FindEntityInSphere for some maps
Reply With Quote #10

Ahh ~~ ; I'm trying again. ^^
__________________
Arkshine is offline
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

Forum Jump


All times are GMT -4. The time now is 17:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode