Skip to content

Segmentation fault running the same code twice #190

@alxx

Description

@alxx

I get a segfault trying to define two handlers successively, even if I off() them after each use.

#!ruby

require 'ruby2d'

set width: 1000

def a
  clear

  evt = on :key_down do |event|
    close if event.key == 'return'
  end

  show

  off evt
end

a
a

puts 'end'

What happens is that I start the script, the first a is called, I press Enter, the same method is called again, I press Enter again and so close is called, then the method ends, then the script ends... then Ruby segfaults:

Screenshot 2021-02-15 at 21 09 42

I'm on macOS 10.15.7 with ruby 2.5.5, and ruby2d 0.9.5 which is the latest at the time I write this.

The reassignment of the event handler actually works fine (I've checked using a bit more code), the problem is that as soon as assign the key_down event the second time, and I call close and the script reaches its natural end (the "end" at the end is printed) then Ruby crashes with a segfault.

It's not a particularly big issue, since the script ends anyway, but it prevents me from exiting with a shell status of 0.

Is there an easy fix to this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions