ID:1417019
 
BYOND Version:501.1216
Operating System:Windows 7 Ultimate 64-bit
Web Browser:Chrome 30.0.1599.101
Applies to:Dream Daemon
Status: Verified

A member of our crack team of bug testers has verified that this issue is reproducible, and has handed it off to the development team for investigation.
Descriptive Problem Summary:
Code in one of my classes has, after formatting and documenting the class, begun to throw an error wherein a class function, while trying to access a variable of the class on which that function has been called, throws a null reference exception. No code changes have occurred

Numbered Steps to Reproduce Problem:

Code Snippet (if applicable) to Reproduce Problem:
Full code file available in StreamReader.dm in this library.

StreamReader
var
SeekPosition = 1
TextFile

-snip-

proc
EOF(var/Pos = SeekPosition)
. = Pos > lentext(TextFile) // This is line 89

-snip-

Find(var/Needle, var/Start = Index(), var/End = 0)
if (EOF(Start) && End >= 0)
return
if (End < 0)
return findtextEx(TextFile, Needle, End)
. = findtextEx(TextFile, Needle, Start, End)


Expected Results:
Previous behaviour; return the logically expected boolean value of the comparison

Actual Results:
runtime error: Cannot read null.TextFile
proc name: EOF (/StreamReader/proc/EOF)
source file: StreamReader.dm,89
usr: Topkasa (/mob/Soldier)
src: /StreamReader (/StreamReader)
call stack:
/StreamReader (/StreamReader): EOF(1)
/StreamReader (/StreamReader): Find("\"", 1, 0)

Does the problem occur:
Every time? Or how often? Every time
In other games? Not testable
In other user accounts? Not tested
On other computers? Not testable

When does the problem NOT occur?
when lentext(TextFile) is changed to lentext(src.TextFile)

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? Worked previously in 501.1216, before formatting with comment blocks.

Workarounds:
Explicitly reference src before attempting to access TextFile
No other variables named "TextFile" are defined anywhere in the project. Literally the only change that occurred between this code working and this code not working was adding a large amount of commenting before each proc, as documentation.
I believe this is a longstanding bug (there's already a report on this somewhere) involving src.var references as the default value for a var.

Try some changes as a workaround:
    proc/EOF(var/Pos)
if(!isnull(Pos)) Pos = SeekPosition
. = Pos > length(TextFile) // lentext is deprecated

proc/Find(var/Needle, var/Start, var/End = 0)
if(isnull(Start)) Start = Index()
if (EOF(Start) && End >= 0)
return
if (End < 0)
return findtextEx(TextFile, Needle, End)
. = findtextEx(TextFile, Needle, Start, End)

I've looked into this issue before but it seems to be a nasty one to root out.
I keep forgetting that lentext() is depreciated. At least I know what causes the bug, so I can avoid it in future. Thanks!
Stephen001 changed status to 'Verified'