[BUG?] Behavior of application changes when adding non-relevant puts

F

Felix Nawothnig

Hi.

Seems I ran into a Heisenbug - the behaviour of my application changes
when I add or remove non-relevant code somewhere - seems it doesn't
really matter where. For that reason I can't really debug or isolate the
bug. :/

I've uploaded the application at:

http://noegnud.sf.net/flgr/foobar.tar.gz

It's about 630 lines. It's a incomplete framework for (german)
textadventures (sorry about the german text - all classnames etc. are
english tho)

At basicthing.rb:315 I added a puts which made the program work:

flexo@majestix foobar $ ruby gold.rb
...
{:ipreps=>[], :verb=>["s\374den", "s"], :dpreps=>[]} (sueden == south)
{:ipreps=>[], :verb=>["norden", "n"], :dpreps=>[]} (norden == north)
Heisenbug!
Du bist in einem dichtem Nadelwald. (This is the description of the new
room - the player went to north)

The loop at basicthing.rb:248-323 is supposed to iterate through all
actions until it finds a matching one (checking the prepositions and
number of objects) and then executes the action's proc.

(The action for "n" (short for "Norden" - north in german) is defined
at evolution.rb:20.)

When I remove basicthing.rb:315 I get:
{:ipreps=>[], :verb=>["i", "inv", "inventar"], :dpreps=>[]}
{:ipreps=>[], :verb=>["osten", "o"], :dpreps=>[]}
{:prefix=>["runter", "herunter", "raus", "heraus"], :ipreps=>["vom",
"von", "aus"], :verb=>["n", "nimm", "nehm", "nehme"], :iobj=>:eek:ptional,
:dobj=>:required, :dpreps=>[]}
{:ipreps=>[], :verb=>["unten", "u"], :dpreps=>[]}
{:ipreps=>[], :verb=>["s\374den", "s"], :dpreps=>[]}
{:ipreps=>[], :verb=>["norden", "n"], :dpreps=>[]}
{:ipreps=>[], :verb=>["oben", "ob"], :dpreps=>[]}
{:ipreps=>[], :prefix=>["um"], :verb=>["schau", "schaue"],
:dobj=>:eek:ptional, :dpreps=>[]}
{:ipreps=>[], :prefix=>["hin", "rein", "herein"], :verb=>["geh",
"gehe"], :dobj=>:required, :dpreps=>["nach", "zum", "zu", "in"]}
{:ipreps=>[], :verb=>["westen", "w"], :dpreps=>[]}
Ich verstehe nicht.

("Ich verstehe nicht" == "I don't understand" - no matching action could
be found)

As you can see it did check for the "move north" action:

{:ipreps=>[], :verb=>["norden", "n"], :dpreps=>[]}

But for some reason it decided that it doesn't match. I can't figure out
why since adding debug-statements breaks/unbreaks it again...

Actually the "puts" doesn't really matter - removing or adding more
rooms or objects causes the behaviour to change, removing properties of
objects does, hell, even changing the (ignored) return-value of some
#properties methods does.

Running it with -d also makes the bug go away for me.
So does set_trace_func().

Someone in #ruby-lang reported the opposite behaviour with the same code
(breaks *with* the puts, runs fine without) and different behaviour
between different ruby versions.

22:41 <@dblack> fn: you can use me as a witness if you want :)

I'm not doing really exotic stuff so... looks like a ruby-bug for me.

Would be nice if someone would take a look at it.

-flexo
 
S

Simon Strandgaard

Felix said:
Seems I ran into a Heisenbug - the behaviour of my application changes
when I add or remove non-relevant code somewhere - seems it doesn't
really matter where. For that reason I can't really debug or isolate the
bug. :/

I took a very quick look at it.

Ruby outputs lots of warnings.. what about getting rid of these first?
Output attached. You way want to set the RUBYOPT environmentvar = 'w'

Another thing is that you make heavy usage of the upper ASCII range 128-255,
this may cause different behavier with different locale.

Sorry, I couldn't find the bug.

--
Simon Strandgaard


server> ruby -w gold.rb
/basicthing.rb:106: warning: (...) interpreted as grouped expression
/noun.rb:61: warning: `*' interpreted as argument prefix
/noun.rb:4: warning: method redefined; discarding old noun
/noun.rb:12: warning: method redefined; discarding old syn
/basicthing.rb:153: warning: instance variable @dark not initialized
Du befindest dich in einem dichtem Fichtenwald. Es hat gerade geregnet und Wasser tropft von den Bäumen. Die Erde unter dir ist aufgewichen und du hinterläßt sichtbare Spuren in ihr.
Ich kann nach: Osten, Norden, Westen, Süden
 
F

Felix Nawothnig

Ruby outputs lots of warnings.. what about getting rid of these first?

Looked through it - they are not related to my problem. The lines
causing
warnings work exactly as they are supposed to.
Another thing is that you make heavy usage of the upper ASCII range
128-255, this may cause different behavier with different locale.

Maybe it would cause outputting some strange chars - but certaintly not
the problem I'm encountering.

-flexo
 
S

Simon Strandgaard

Felix said:
Looked through it - they are not related to my problem. The lines
causing warnings work exactly as they are supposed to.


Maybe it would cause outputting some strange chars - but certaintly not
the problem I'm encountering.

Some other issues I see, which could be dangerous.

'evolution.rb', you use bind/call/ancestors in a creative way.
Your Object#evolve are also suspicious.
If I were you I would unittest this file carefully.

'noun.rb', Kernel.send/define_method.
Also suspicious to me.

'basicthing.rb' send feels kludgy.

It isn't clear to me what is going on, because of the above
things you are using. I would try to use OOP, rather than
Kernel.send/bind.. etc.
 
D

David Alan Black

Hi --

Simon Strandgaard said:
Some other issues I see, which could be dangerous.

'evolution.rb', you use bind/call/ancestors in a creative way.
Your Object#evolve are also suspicious.
If I were you I would unittest this file carefully.

'noun.rb', Kernel.send/define_method.
Also suspicious to me.

'basicthing.rb' send feels kludgy.

It isn't clear to me what is going on, because of the above
things you are using. I would try to use OOP, rather than
Kernel.send/bind.. etc.

Not a big fan of introspection and/or intercession, I guess :) In any
case I think there's more to it than this -- after all, those are
perfectly legitimate Ruby techniques, and although they can be used
incorrectly, using them does not fully explain why this change:

$ diff basicthing.rb basicthing.rb.changed
315c315
< #puts "Heisenbug!"
---
puts "Heisenbug!"

would cause a dramatic difference in runtime behavior (in Ruby 1.8.1).
If Ruby's comment-parsing changes as a result of using send, I think
it's in everyone's interest to be aware of this :)

(Not that I know exactly what's happening -- I wish I did -- still
scrutinizing it....)


David
 
S

Simon Strandgaard

David Alan Black said:
Not a big fan of introspection and/or intercession, I guess :) In any
case I think there's more to it than this -- after all, those are
perfectly legitimate Ruby techniques, and although they can be used
incorrectly, using them does not fully explain why this change:

I like meta programming/eval with Ruby.. However I test things
carefully in order to convince myself that it works correct.
If I see no tests then I am of cause sceptical.

Weird things may occur when instance_eval'ing a randomized string :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top