Skip to content

Make get_stack() available in release/debug export templates as well as in the editor #105

Closed
@rslepon

Description

@rslepon

Describe the project you are working on:
I am developing a story-driven turn-based tactical game.

Describe how this feature / enhancement will help your project:
Bugs happen even in released games. Having an error log with a stack trace would help in debugging.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
N/A

Describe implementation detail for your proposal (in code), if possible:
Currently get_stack() seems to work only in the editor, as far as I can see. I believe it may be even more useful in the exported exe (in debug and release mode), so I suggest making it work there too.

Here is a function I was planning to use in my game as a replacement for assert():

# replacement for assert, aborting in debug mode, logging in debug and release modes
func ass (cond :  bool, # if conditional is not true, pretty fatal
          msg  := ""    # message to print to log
         ) -> void:
   var fh  := File.new() # file handle
   var err := OK         # error code

   # if failed
   if not cond:

      # open new file
      err = fh.open(D.LOG_FILE_PATH_FULL, File.READ_WRITE)
      assert(err == OK)

      # write to log
      fh.store_line("%d: %s" % [OS.get_ticks_msec(), msg])
      fh.store_line(str(get_stack()))

      # close file
      fh.close()

      # abort in debug mode
      assert(cond)

It works just fine, except that get_stack() returns an empty array in the exported exe (regardless of whether "Export With Debug" is checked or not), where it is most needed, since in the editor the information is already available in the debugger.

P.S. I expect the same could be said for print_stack() too.

P.P.S. I am suggesting to add this as an optional project (or export) setting (off by default). If one wished to pay the performance penalty for the added debug capability (I would), then one would enable that setting.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Not that I can see.

Is there a reason why this should be core and not an add-on in the asset library?:
It's a very basic debug feature that I would expect it to be useful for every game being developed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions