Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 3941 - Do not repeatedly raise new sets of keystrokes when modals pop (stack overflow) #3949

Draft
wants to merge 7 commits into
base: v2_develop
Choose a base branch
from
5 changes: 5 additions & 0 deletions Terminal.Gui/Application/Application.Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ public static bool RunIteration (ref RunState state, bool firstIteration = false
return firstIteration;
}

internal static void RaiseIteration ()
{
Iteration?.Invoke (null, new IterationEventArgs ());
}

/// <summary>Stops the provided <see cref="Toplevel"/>, causing or the <paramref name="top"/> if provided.</summary>
/// <param name="top">The <see cref="Toplevel"/> to stop.</param>
/// <remarks>
Expand Down
9 changes: 9 additions & 0 deletions Terminal.Gui/Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
/// <summary>Gets all cultures supported by the application without the invariant language.</summary>
public static List<CultureInfo>? SupportedCultures { get; private set; } = GetSupportedCultures ();

/// <summary>
/// Maximum number of iterations of the main loop (and hence draws)
/// to allow to occur per second. Defaults to 25 which is a 40ms sleep
/// after iteration (factoring in how long iteration took to run).
/// <remarks>Note that not ever iteration draws (see <see cref="View.NeedsDraw"/>).
/// Only affects v2 drivers.</remarks>
/// </summary>
public static ushort MaximumIterationsPerSecond = 25;

/// <summary>
/// Gets a string representation of the Application as rendered by <see cref="Driver"/>.
/// </summary>
Expand Down Expand Up @@ -63,7 +72,7 @@
{
Rune rune = contents [r, c].Rune;

if (rune.DecodeSurrogatePair (out char [] sp))

Check warning on line 75 in Terminal.Gui/Application/Application.cs

View workflow job for this annotation

GitHub Actions / build_and_test_debug (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 75 in Terminal.Gui/Application/Application.cs

View workflow job for this annotation

GitHub Actions / build_and_test_debug (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 75 in Terminal.Gui/Application/Application.cs

View workflow job for this annotation

GitHub Actions / build_and_test_debug (macos-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 75 in Terminal.Gui/Application/Application.cs

View workflow job for this annotation

GitHub Actions / build_release

Converting null literal or possible null value to non-nullable type.
{
sb.Append (sp);
}
Expand Down
5 changes: 4 additions & 1 deletion Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@
public void Iteration ()
{
DateTime dt = Now ();
int timeAllowed = 1000 / Math.Max(1,(int)Application.MaximumIterationsPerSecond);

IterationImpl ();

TimeSpan took = Now () - dt;
TimeSpan sleepFor = TimeSpan.FromMilliseconds (50) - took;
TimeSpan sleepFor = TimeSpan.FromMilliseconds (timeAllowed) - took;

Logging.TotalIterationMetric.Record (took.Milliseconds);

Application.RaiseIteration ();

if (sleepFor.Milliseconds > 0)
{
Task.Delay (sleepFor).Wait ();
Expand Down Expand Up @@ -151,7 +154,7 @@

private void SetCursor ()
{
View? mostFocused = Application.Top.MostFocused;

Check warning on line 157 in Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs

View workflow job for this annotation

GitHub Actions / build_and_test_debug (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 157 in Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs

View workflow job for this annotation

GitHub Actions / build_and_test_debug (macos-latest)

Dereference of a possibly null reference.

if (mostFocused == null)
{
Expand Down
9 changes: 8 additions & 1 deletion UICatalog/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,20 @@ private void OnApplicationOnIteration (object? s, IterationEventArgs a)
}
}

private HashSet<Scenario> _scenariosRun = new HashSet<Scenario> ();
private void OnApplicationNotifyNewRunState (object? sender, RunStateEventArgs e)
{
// We are just returning to the same scenario
if (!_scenariosRun.Add (this))
{
return;
}

SubscribeAllSubviews (Application.Top!);

_currentDemoKey = 0;
_demoKeys = GetDemoKeyStrokes ();

Application.AddTimeout (
new TimeSpan (0, 0, 0, 0, BENCHMARK_KEY_PACING),
() =>
Expand Down
1 change: 1 addition & 0 deletions UICatalog/UICatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@

private static void BenchmarkAllScenarios ()
{
Application.MaximumIterationsPerSecond = ushort.MaxValue;
List<BenchmarkResults> resultsList = new ();

var maxScenarios = 5;
Expand Down Expand Up @@ -1356,7 +1357,7 @@
//CanExecute = () => false
});

return menuItems.ToArray ();

Check warning on line 1360 in UICatalog/UICatalog.cs

View workflow job for this annotation

GitHub Actions / build_release

Nullability of reference types in value of type 'MenuItem?[]' doesn't match target type 'MenuItem[]'.
}

// TODO: This should be an ConfigurationManager setting
Expand Down
Loading