Double free or corruption (!prev)

Recently I want to write a program to read script files like this: Untitled - Pastebin.com


I know little about C, so as the ‘double free’. And I am confused.
Here is my code: (it truly takes time for me to locate the problematic function, since this error msg has no traceback…)

      
  def ArcaeaInspector.update_txt(new_text : String, line_num : Int32)
    case line_num
    when 0
      tx = @@txta
    when 1
      tx = @@txtb
    when 2
      tx = @@txtc
    end
    tx = tx.not_nil!
    tx.string = new_text
    lb = tx.local_bounds
    tx.origin = SF.vector2f lb.left + lb.width / 2, lb.top + lb.height / 2
    tx.position = SF.vector2f(
      @@window.size.x / 2,
      @@window.size.y - @@window.size.y / 5 + line_num * 20)
  end

Here is where this func is called:

  def say(content : Array(String))
      ArcaeaInspector.clear_txt
      i = -1
      content.each do |t|
        SF.sleep SF.seconds 1.5
        i += 1
        ArcaeaInspector.update_txt t, i
      end
      SF.sleep SF.seconds 1
      ArcaeaInspector.show_arrow
    end

The code is at my github repository

By the way, I’ve also tried run the program in release mode, and the error exists still.
What’s more, this occurs “sometimes”.

So… What’s the error?

3 Likes