Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Hanging: Would this work?

I wasn't sure where to put this, it's more a question than a request. Meh.

You know the script hanging bug? Well, it happens when the graphics haven't been updated for a certain amount of time. So, would it be possible to set up a script to check if the graphics haven't been updated for 1 frame less than the cutoff, and show a small image so that the graphics update?

This may just be complete nonsense, but it made sense in my head... so...
 
Instead of showing a picture, you could just call Graphics.update,

The problem is...  Where would you put it?

That error usually occurs when you have a script or event that is (capitalizing?) the processor,
and not allowing the Graphics.update method to be called in the normal fashion.

Also, you would have to track time using the Time class, since the Graphics.update method is
responsible for advancing game_time & frame_count.

Probably better that you write/use code that doesn't do that!!  :scruff:

Quite honestly, if the game just sits there for more than 10 seconds without doing anything,
especially with today's "A.D.D." generation, the player is going to kill the game, and go find a
new one.

Just my opinion, (see disclaimer below)

Be Well
 

Zeriab

Sponsor

I am a bit confused as to what your goal is... Is it about showing a loading picture when graphics.update hasn't been called for a while or is it to get rid of the script hanging error?
Well, either way turns towards a solution of using threads.
Here is a script snippet where the Graphics module is altered to keep track of last time Graphics.update was called.
A separate thread is started. It keeps track of how long time has passed since the last time Graphics.update was called. if more than 4 seconds has passed, it will call Graphics.update. (It will only check once every second)
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

You must note that if you use this snippet your code becomes indeterministic. There is the potential of Graphics.update being called from at any time within your main code, which means any area dealing with graphics may potentially generate errors. It may just be graphical bugs or it may be bugs that will actually crash your game. I can't tell you. All I can tell you is that updating the graphics while drawing something on a bitmap is potentially dangerous. In addition. Recreating a situation where you previously got an error may not yield that error again, or may only yield it sometimes.

So yeah, this is not a snippet you should mindlessly place in your project.
It would be better if you explained why you want to prevent the script hanging bug. In which situation does it happen. Has it something to do with establishing a connection to a server/client? Some large generating mechanism/script?

*hugs*
- Zeriab
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top