ID:109785
 
Not a bug
BYOND Version:479
Operating System:Windows Vista Home Premium
Web Browser:Firefox 3.6.13
Applies to:DM Language
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
When you create a turf, references to the turf that was previously at that spot get updated to the new turf. This even happens for src in procs running on that turf.
Additionally, sleeping and spawned procs running on that turf continue to run with the wrong value of src.

Numbered Steps to Reproduce Problem:
1. Compile the code below (it's a complete project by itself) and run it
2. Right click an "a" and select the "change" verb.
3. Look in the output window.

Code Snippet (if applicable) to Reproduce Problem:
turf
a
text = "a"
// run this to demonstrate the problem with src
verb/change()
set src in view()
spawn(5)
world << "spawned code, src.type is [src.type]"
new /turf/b(src)
world << "src.type is [src.type]"
b
text = "b"
// run this to demonstrate the problem with a normal variable
verb/change()
set src in view()
var/turf/a/a = locate() in view()
a.change()
world << "a.type is [a.type]"

world
maxx = 10
maxy = 10
turf = /turf/a


Expected Results:
References to the turf get updated to null, and sleeping and spawned procs running on the turf get terminated.

Actual Results:
References to the turf get updated to point to the new turf, and sleeping and spawned procs continue running with the wrong value of src

Does the problem occur:
Every time? Or how often? Every time
In other games? Yes
In other user accounts? Untested
On other computers? Untested

When does the problem NOT occur?
When the new turf was created by deleting an existing turf with del instead of creating a new turf with new.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
Untested

Workarounds:
Explicitly set src to null, or be careful not to use it after creating the new turf. (That doesn't solve the problem with suspended code, though)
Turfs are never created or destroyed except when world.maxx/y/z change. When you call new/turf() you're replacing an existing turf, but the reference does not change. The reference only changes if the global map dimensions update, and even then sleeping procs will continue to reference the same turf because they get updated too.

If you need a sleeping or spawned turf proc to be able to detect if the turf has been changed to a new type, you have to put checks in for that yourself. In the vast majority of games however, the existing behavior is beneficial.