Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

DragonRuby Game Toolkit

An intuitive 2D game engine. Fast, cross-platform, tiny, hot loaded. · By DragonRuby

"The following hash reached a nil thrashing limit"

A topic by tncowart created Aug 14, 2019 Views: 234 Replies: 2
Viewing posts 1 to 3
(1 edit)

What does this mean?

ERROR:
The following hash reached a nil thrashing limit.
Here are the details:
{
  :entity_id => 1,
    :tick_count => 2,
    :__thrash_count__ => {
                         :+ => 6
                       },
    :player => #<Player:0x118b58f60>,
    :obstacles => [[590, 0, 50, 50, 255, 0, 0], [640, 0, 50, 100, 0, 0, 200], [710, 50, 200, 5, 200, 0, 200]]
}
member: [+]
attribute: [obstacles].

I get it when I use "attr_accessor [symbols]" in my Player class and then access my instance variables using the generated accessors.

I get around this by using instance variables directly but it feels weird and un-ruby-ish to do so.

 Is this a limitation of DragonRuby or DragonRuby GTK?

Thank you!

(1 edit)

I also notice that I can use generated accessors from outside the class. Basically, given

class Foo
    attr_accessor :bar
    def initialize
        @bar = 0
    end
    def baz
        bar += 1
    end
end
f = Foo.new

This is fine:

f.bar
f.bar = 1

This crashes the engine with the above error because the 'baz' method uses the 'bar' accessor internally:

f.baz
(2 edits)

Hi, not a DragonRuby developer here, but I think it should be `self.bar += 1` and not `bar += 1` because you are assigning a value to `bar` , otherwise if not prepending `self.`, `bar` is then treated as a local variable:

I tested below, and it works:

```ruby
class Foo
  attr_accessor :bar

  def initialize
    @bar = 0
  end

  def baz
    self.bar += 1
  end
end

def tick(args)
  args.state.f ||= Foo.new
  args.state.f.baz
  puts args.state.f.instance_variable_get(:@bar)
end
```

```
1
2
3
4
5
6
7
8
9
...
```

If I changed above into:

```
  def baz
    bar += 1
  end
```

... I get the same errors as yours:

> ERROR. The following hash reached a nil thrashing limit.

However, copying the code into my local mri ruby installation, I get the more familiar error:

NoMethodError (undefined method `+' for nil:NilClass)

Because `bar += 1 , translates to `bar = bar + 1`, and `bar`  at that point is not defined yet, so `bar (undefined) + 1` throws that `nil:NilClass` error.
Having said this though, I think the `mri` error message better described what the error was, though maybe because I'm just not used to DragonRuby errors yet.