Proc stored somewhere?

Hello, I'm currently working on my tbs, I've changed how reaction works and now they use a stack that I've defined. Because of this I have changed huge chunks of the code so this might be a reason why I encounter my current issue, note that I'm still experimenting from a save file so maybe this is the source of the bug I'm encountering.

When I perform a deep copy of a battler with:
@user = Marshal.load(Marshal.dump(user))
It sometimes breaks with error TypeError: no marshal_dump is defined for class Proc
I say sometimes because it did not break with my actors but it does with the enemies.
I am aware that the class Proc cannot be saved, so this error means that inside my battler, there is a (direct or indirect) reference to a Proc object, right?
As such, I've looked where such Proc could have been instantiated, and I only found two places that are related to the Interpreter:
- during choices, where a Proc is stored into $game_message,
- when calling a battle (but I bypass it with a script of @Another Fen that replaces this Proc with a class that can be saved).

By checking the code, I can't find any place where $game_message or its argument could have been stored, and in fact by adding this scriptlet before main:
Ruby:
class Proc
  alias proc_init initialize
  def initialize(*args)
    puts "Procing a Proc..."
    proc_init(*args)
  end
end
I did not get any message on the console during my game.

So, either my save file broken and some weird low-level stuff is happening to believe that an object is a Proc. Or a Proc object was created before my added scriptlet and is stored somewhere?
My question is the following: how can I identify such Proc easily and maybe track down which objects store it?
I will try later with a new game, but I'm currently very curious how an object that can't be saved could be identified afterwards.

PS: I'm using the backtrace script by Solistra but the backtrace of the error does not go any further than the call to dump so I don't have any more informations than this.
PS2: I just saved the game once more during the battle (so with the troop members too) and nothing breaks, but the dump error still arises when I try to dump an enemy, so I guess the context is important.

Edit: turns out saving the battle fails a few turn after (and before the crash ofc), so something happens in between.

Edit2: Ah! It was indeed my fault 🙂 Actually what happened was that I applied too much Hime's recommendation on formulas which turns a formula (a string) into a lambda. But lambdas cannot be saved: what I did (and that was my mistake) was store the lambda into a RPG::UsableItem, which can sometimes be stored into an action which is contained into a battler, leading to unsavable battlers because of this.

By the way I wrote this code to help me keep track of the unwanted object if someone needs it at some point:
Ruby:
class TrackObject
  #parent is the object to scan, obj_class is the class to identify
  def initialize(parent, obj_class)
    @obj_class = obj_class
    @performed = []
    r = recursive_check(parent)
    if r
      puts r
    else
      puts "Could not find class #{obj_class}"
    end
  end
 
  #return a string if object is found, false otherwise
  def recursive_check(obj)
    return "found #{obj}" if obj.is_a?(@obj_class)
    return false if @performed.include?(obj)
    @performed.push(obj)
    if obj.respond_to?(:to_a)
      obj.to_a.each_with_index do |x, i|
        r = recursive_check(x)
        return r + " at index #{i} in #{obj.class}" if r
      end
    end
    obj.instance_variables.each do |v|
      r = recursive_check(obj.instance_variable_get(v))
      return r + " as #{v} in #{obj.class}" if r
    end
    return false
  end
end

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/proc-stored-somewhere.181819/