=begin #=============================================================================== Title: System Stack Debugger Author: Hime Date: Aug 12, 2013 -------------------------------------------------------------------------------- ** Change log Aug 12, 2013 - initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script provides a way for scripters or script users to debug any issues related to SystemStackError. It prints out a log of the issue that should be useful to anyone that understands what it's saying. -------------------------------------------------------------------------------- ** Installation Place this script below Materials and above Main You may also want to use the Full Input Stacktrace script http://himeworks.com/2013/06/09/custom-main-full-error-backtrace/ -------------------------------------------------------------------------------- ** Usage You will use this script only when you encounter a SystemStackError exception. To use this script, you simply need to add this line to your code TH.trace_system_stack TH.trace_system_stack(n) Where `n` is the number of method calls that are allowed to be made before this script assumes there is a problem. If no value is provided, then it assumes the default value specified in the configuration below. If you are not sure what is causing the error, you can install the Full Input Stacktrace script: it will tell you a particular line has caused the stack error. Find this line and then place the trace code above it. #=============================================================================== =end $imported = {} if $imported.nil? $imported["TH_SystemStackDebugger"] = true #=============================================================================== # ** Configuration #=============================================================================== module TH module System_Stack_Debugger # number of method calls to make before assuming there is a problem Threshold = 300 # if you prefer reading from top to bottom Reverse_Stack = false #=============================================================================== # ** Rest of Script #=============================================================================== def self.log_system_stack f = File.new("SystemStack.txt", "w") f.write("System Stack Trace Log\n") f.write("Send this to a scripter to help troubleshoot your problem\n") f.write("=============================================================\n") scripts_name = load_data('Data/Scripts.rvdata2') scripts_name.collect! {|script| script[1] } backtrace = [] caller.each_with_index {|line,i| if line =~ /{(.*)}(.*)/ backtrace << (scripts_name[$1.to_i] + $2) elsif line.start_with?(':1:') break else backtrace << line end } error_line = backtrace.first backtrace.delete_at(0) backtrace.reverse! if Reverse_Stack f.write("System stack error detected\n") backtrace.each do |line| f.write("\tfrom " + line + "\n") end f.close end end def self.trace_system_stack(threshold=TH::System_Stack_Debugger::Threshold) return if caller.length < threshold TH::System_Stack_Debugger.log_system_stack raise "System Stack Debug." end end