No Hang Script
#1
As many of you probably know you get a 'Script Hanging' error if a script takes too long to process.

More accurately, if the Graphics.update is not called in about 10 seconds the engine will assume an endless loop or something similar has happen. It will therefore give the 'Script Hanging' error.

This code snippet works by calling Graphics.update if this has not happened in a long time. A separate thread is running which checks up on the time. It should not affect the speed of the main thread in any significant way. It will not work if you have DLL calls which takes too long though.

THIS IS A SCRIPT YOU DON'T JUST ADD

Adding this script comes at the of your code becoming non-deterministic. This is bad, very bad. Also I do not have a monitor on critical parts, which gives the possibility of race conditions. I think that Graphics.update does have mutual exclusion, but I am not sure.

And even if it has, what do you think happens if Graphics.update is called while you are in the process of creating a sprite?
I expect this mainly to be for scripters to help their debugging and testing of stuff.

Since the script will not call Graphics.update unless 4 seconds has passed since the last call to Graphics.update I do not expect it will have too much of an effect.

Code:
if @zer_no_hang_stack.nil?
  ##
  # Change the Graphics module so it contains the time of the last update
  # Add a getter for the time property
  #
  module Graphics
    # Alias the update method (you have to do it this way since Graphics is a module)
    class << self
      alias no_hang_update update
    end
    ##
    # Change the update method
    #
    def self.update
      @@time = Time.now
      self.no_hang_update
    end
    ##
    # Retrieve the Time at the last update
    #
    def self.time
      # Protection if this method is called before the first update
      @@time = Time.now if @@time.nil?
      return @@time
    end
  end
  
  ##
  # A separate thread that will run and keep track of the time since the last
  # update
  #
  Thread.new {
    loop do
      # Lets the thread sleep for a while to minimize CPU usage
      sleep 1
      # If more than 4 seconds has passed since the last update
      if Time.now - Graphics.time > 4
        # Update the graphics
        Graphics.update
      end
    end
  }
  
  @zer_no_hang_stack = true
end

Use it wisely and only if there is an actual need.

*hugs*
- Zeriab
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Text Scroll Script - Enhanced DerVVulfman 23 34,880 02-18-2021, 04:16 AM
Last Post: DerVVulfman
   Cursor Script Selwyn 7 15,660 09-28-2019, 02:13 PM
Last Post: DerVVulfman
   ACBS FIX SCRIPT #2: Advanced Cry Correction DerVVulfman 1 4,846 08-09-2019, 03:42 PM
Last Post: aeliath
   ACBS FIX SCRIPT #1: Victory Cries Patch DerVVulfman 1 4,835 08-08-2019, 02:53 PM
Last Post: aeliath
   Spritesheet Generator Conversion Script DerVVulfman 0 4,352 11-21-2018, 04:48 AM
Last Post: DerVVulfman
   Neo Mode 7 Script by MGCaladtogel MGC 59 126,753 09-29-2017, 03:48 AM
Last Post: DerVVulfman
   Longer Script Calls LiTTleDRAgo 0 5,044 05-17-2017, 12:36 AM
Last Post: LiTTleDRAgo
   SLOLS: Snake Look-alike on Load Script Zeriab 3 11,464 05-14-2017, 06:25 PM
Last Post: LiTTleDRAgo
   Character Select Script Selwyn 3 10,941 03-07-2017, 04:14 AM
Last Post: JayRay
   ELSA (Event Layering Script Advance) JayRay 0 6,074 02-25-2015, 04:15 AM
Last Post: JayRay



Users browsing this thread: 1 Guest(s)