RPTools / maptool

Virtual Tabletop for playing roleplaying games with remote players or face to face.
http://rptools.net
GNU Affero General Public License v3.0
803 stars 263 forks source link

Maptool needs an emergency Macro Abort function #2227

Open Ltheb opened 4 years ago

Ltheb commented 4 years ago

Is your feature request related to a problem? After losing another 3 hours of time writing a macro to a probably badly written While() loop, I feel Maptool needs a Keyboard command with the ability to end all currently running macros. During an endlessly processing while loop, I could not save, execute any command, or do anything except helplessly watch my ram use slowly climb and knew I should have saved hours ago, and that there was nothing I could do. The life of a programmer, eh? Having had similar issues in the past (such as with a player, in the older versions of maptool, putting a "[Token_Property]" entry in another Token Property (Prompting endless popups on token mouseover), I feel these problems need some sort of fix.

Describe the solution you'd like My proposal is to keep maptool responsive to a specific keyboard command during macro processing. The command should be definable by the user. By default, something like Ctrl+Alt+Shift+T (Chosen to reduce likelihood of it being hit at random) but any key combo that make sense is fine.

The above proposal is designed to aid programmers, both amateur and experienced, from losing hours of time coding due to the wrong > or < symbol in a while loop, or any of the other ill-advised stupid things people do while writing code at odd hours of the night. :P With this function, a user could abort their bad coding mistake, look for what may have caused the problem, debug it, and resume operation without having to task-kill maptool and lose unsaved work.

Describe alternatives you've considered Other options might just include maptool warning if it is locked up for a length of time (1+ Minute) and auto-aborting, or prompting for an auto abort, but that might be messy for someone attempting a large batch function macro that they understand may take a some time, nor would that help if they get stuck in one of those endless "please define this variable" window spam situations.

This feature would likely require hooks into the maptool macro and token function to allow it to catch those functions and kill them, and a function with a high priority for keypress reception, which requires a special case, since maptool, while locked up running some endless macro or spitting out infinite error messages, is basically dead. It may as well just kill it's own process, since that is the action the user must take.

Phergus commented 4 years ago

You do know there is autosave of campaigns? The default is every 5 minutes.

Ltheb commented 4 years ago

I am. I have it disabled. I am aware that my decision there is stupid, and 100% my fault, but I have a very large campaign that takes several minutes to save. (@ 128 MB campaign file as of right now, which has not been its largest size) Autosaves (last I checked) grind the server to a halt and were significantly distracting during play. However, I don't think I've run auto save in literal years, so perhaps it runs better. Also, I am not sure about autosaves saving while you have the Edit Macro window open, since I don't think that progress is saved until you hit OK, Apply, or Run Macro. I was going to comment about this in my above write up, but I felt personal use information would have muddied the description.

I appreciate the reminder, and will probably consider testing re-enabling Autosave in the near future.

selquest commented 4 years ago

The built-in recursion/loop limit should prevent actual infinite loops anyway, right? The default limits are 10,000 loops or 150 recursions.

Azhrei commented 4 years ago

The built-in recursion/loop limit should prevent actual infinite loops anyway, right? The default limits are 10,000 loops or 150 recursions.

Yeah, but if it includes those variable pop ups, 10000 loops is a LONG time. Or if macro A loops 10000 times and calls macro b (which also loops 10000 times), it can also take forever.

One option would be a "progress bar" function that has a Cancel button so the user can cancel the macro execution, but that wouldn't help for situations where the infinite loop is the result of a coding error...

I do tend to agree that some way to stop the execution is needed.

selquest commented 4 years ago

Makes sense. I think Craig has said something about macro execution coming off the GUI thread at some point in his plans? That will make this doable.

Ltheb commented 4 years ago

I left my errant While() loop going for a good 5 minutes; it was only processing 2 variables changes; decrementing itself, and adding +1d4 to another variable (Since I needed to test that the code would do the while loop.; Maptool's memory use balloned to ~5 gigs or so before I had to kill it, and the whole window was frozen; even if there was a limit on loops, its set quite high. (Maybe it could be configurable? Perhaps even on a per-macro basis, so as not to mess with preexisting frameworks, etc.)

As for a progress bar with a Stop button? That could become intrusive if it was a popup window. (Multiple called macros could get messy) What if it were in the GUI header bar, by the audio mute and volume slider, or down at the bottom by the status bar? Or it's own window pane, like the player connections window "Currently executing Macros" or some such?

Phergus commented 4 years ago

@Ltheb check the functions for controlling recursion and loop limits.

http://www.lmwcs.com/rptools/wiki/Category:Loop_and_Recursion_limits

Ltheb commented 4 years ago

@Phergus The documentation of those are a little unclear, as while it sets the limits per session, I assume the limit, when set, is server-side (and is a trusted function). Also, with it's limit being minimum 10k loops, I could only set it to higher numbers. Perhaps if it were allowed to be set to lower values, It could have saved me. If that number could be changed and lowered, that might be helpful. Its not like someone is going to accidentally type this, if it is indeed a trusted function; I might set it to something low like 10-100 for a test environment if that were possible, to prevent the very issue that befell me earlier.

bubblobill commented 4 years ago

Ability to interrupt macro execution #1464

Phergus commented 4 years ago

@Ltheb you mentioned wanting to be able to set the limits, I was just pointing out that there are functions for that already. Never used them however nor have I looked at the code for them.

Ltheb commented 4 years ago

@Phergus Yeah, I had no idea those existed, but as mentioned, they seem very limited in their usefulness. My initial suggestion though still feels relevant, IMO; the ability to go "oops, I done goofed" rather than lose hard work seems like a good Quality of Life feature for maptool, making it more user friendly, especially for the amateur coders just trying get a specific function for their game automated or optimized; Many times when doing so, I know I would not do all the proper preparations that I should (pre-opening the wiki; closing other programs, enabling autosave, etc) since "Oh, this will only take like 1 hour" (4 Hours later) "Oh, this might be hard".

That said, I don't know all the hooks and functions that might need to be rewritten to make something like this happen, and if it would take a rewrite of some of those core functions, like rendering and macro processing, it might be better saved for implementation when many other features or QoL updates pile up necessitating them.