View previous topic :: View next topic |
Author |
Message |
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Thu May 03, 2012 11:12 Post subject: bug in GetNearest* function |
|
|
Hi!
Is there a common known problem with GetNearest functions? I ran into this again, and found nothing on these forums about it. It's bugging my spawn-script, when iterating through the waypoints in the area. In my tests, sometimes the iteration miss one waypoint, but replaces it with an other waypoint - so that waypoint found twice.
So that's why i replaced the GetNearestObject function with GetNearestObjectToLocation, but sadly i forgot that ... and probably it happens with other objects too (almost sure about shops). |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Thu May 03, 2012 20:38 Post subject: |
|
|
There's no such bug as far as I know.
Make sure you're not yielding to nwserver when iterating (i.e. storing nNum locally and continuing on in another script) - order is not guaranteed to be the same between VM executions.
Can you show the code that produces such issues? |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Thu May 03, 2012 21:02 Post subject: |
|
|
I had similar issue in AOE OnEnter script which did looped through creatures in radius and some creatures were returned twice or even more times. I tried all GetNearest* functions and even GetObjectInShape but this bug occured in all of them. The only way to solve was to maintain string with IDs of already checked objects. _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Fri May 04, 2012 0:33 Post subject: |
|
|
Yeah, probably all GetNearest* functions are buggy.
I found some references in the Omnibus too. Not so easy to reproduce this bug, but can happen anywhere if the constellations are good. Any new object in the given area can change the results.
So i put together a proof-of-concept-alike demo module, pls check it:
http://steelskies.gotdns.com/download/getnearest.zip
Try it as a DM (if you cannot enter, create a new DM character, i deleted all the default scripts), and check the journal.
thx |
|
Back to top |
|
|
Baaleos
Joined: 02 Sep 2007 Posts: 830
|
Posted: Fri May 04, 2012 16:39 Post subject: |
|
|
I suppose if you think about it, in any programming language - if you try to iterate through a list, and change the list as you are iterating through it - you will cause an exception.
In .Net - it would be a ListHasChanged exception.
Neverwinter Nights doesnt throw the exception that we would expect to see, but it is sort of a given that this sort of thing can occur.
I would imagine that this issue can be made alot more visible by using the GetNextObject function, within a DelayedCommand.
This would break up the Linear execution, and provide more opertunities for the Enumeration to change.
Not forgetting - NWN scripting is single threading - a Single Function/Script runs at any one time - Using Delayed Commands breaks this up though, allowing another script/function to create new objects, even within the iteration of NextObject loops - which I imagine would cause the problem to occur.
The problem that Ravine is having where it is processing the same Waypoint twice, is probably happening because at a lower level within the GetNearest function - all objects are processed as the same type.
a Generic object within the area.
So - even though you are trying to iterate through Waypoints only - it still iterates through the generic objects, but only counts those generic objects if they are of type 'Waypoint'.
It is probably the case that an NPC Spawning in the area, could potentially be offsetting the index within the Areas Objects list.
(Very theoretical - Im sure someone who has disassembled the nwserver.exe binary more than me can explain it in detail). |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sat May 05, 2012 19:39 Post subject: |
|
|
Ravine wrote: | Yeah, probably all GetNearest* functions are buggy.
I found some references in the Omnibus too. Not so easy to reproduce this bug, but can happen anywhere if the constellations are good. Any new object in the given area can change the results.
So i put together a proof-of-concept-alike demo module, pls check it:
http://steelskies.gotdns.com/download/getnearest.zip
Try it as a DM (if you cannot enter, create a new DM character, i deleted all the default scripts), and check the journal.
thx | I've tested this and the result is negative. The order is correct at least on win OS without nwnx. _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Sat May 05, 2012 22:25 Post subject: |
|
|
ShaDoOoW wrote: | I've tested this and the result is negative. The order is correct at least on win OS without nwnx. |
Hm, that is interesting. I tested this on winXP. I'm sure it's bugging on linux server too. I made a video too to demonstrate it.
http://www.youtube.com/watch?v=uiYP2tHqnjk
You did it the same way? |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sun May 06, 2012 2:28 Post subject: |
|
|
Ravine wrote: | ShaDoOoW wrote: | I've tested this and the result is negative. The order is correct at least on win OS without nwnx. |
Hm, that is interesting. I tested this on winXP. I'm sure it's bugging on linux server too. I made a video too to demonstrate it.
http://www.youtube.com/watch?v=uiYP2tHqnjk
You did it the same way? | i did... but without nwnx as I said _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Sun May 06, 2012 2:32 Post subject: |
|
|
Sure, on windows i don't use nwnx. It's a native bug i think. |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sun May 06, 2012 4:59 Post subject: |
|
|
strange i just tried again and had same result as you, seems I havent tried enought first, it works on few spots near VFX and I was standing in one of them at first... _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Sun May 06, 2012 11:25 Post subject: |
|
|
Yeah, i wasn't too clear about it in my previous post. Results can change by pixels. I just realised that this fooked up some of my quests and shops, where used GetNearestObject* functions.
In critical scripts (spawn for example) i changed them to GetFirst/GetNextObjectInArea, that is stable, but i think thats slower (didn't done benchmark, just a guess).
Now, if we know it's buggy, is there any chance for a fix? |
|
Back to top |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Sun May 06, 2012 23:45 Post subject: |
|
|
I tried to set Z position of the object which location is used as start to 0.0 and it worked everywhere. I couldnt find the spot where would be results broken.
I dont know how to fix it in engine but i would try to use custom function using getnearestobjecttolocation with the input location adjusted the Z position to 0.0 _________________ Community Patch / NWNX Patch / NWNX Files / NWNX Connect |
|
Back to top |
|
|
Lokey
Joined: 02 Jan 2005 Posts: 158
|
Posted: Tue May 08, 2012 2:08 Post subject: |
|
|
The only problem I've encountered is damage/effects/death on stuff in a loop, if you don't delay it or perform outside the get/next loop, the loop will keep on running until TMI.
Not seeing anything obvious about GetFirst/NextInShape these failing these days. _________________ Neversummer PW NWNx powered mayhem |
|
Back to top |
|
|
|