Skip to content

Commit

Permalink
Rate-limit the output of inklecate after generating 1000 lines, to pr…
Browse files Browse the repository at this point in the history
…event choking Inky in infinite loops
  • Loading branch information
joethephish committed Jun 10, 2024
1 parent 5c20d66 commit da3d4df
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions inklecate/CommandLinePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public void Begin()

void EvaluateStory ()
{
int lineCounter = 0;

while (story.canContinue) {

story.Continue ();
Expand Down Expand Up @@ -238,6 +240,17 @@ void EvaluateStory ()

_errors.Clear();
_warnings.Clear();

// Start limiting the output rate if it looks like we might be
// getting into an infinite loop. This prevents Inky from getting
// choked up because its IPC gets overloaded from useless data,
// which can even prevent internal renderer processes from working.
// I don't really like putting artificial human-scale limits on
// computer processing, but not sure what the alternative is?
lineCounter++;
if( lineCounter > 1000 ) {
System.Threading.Thread.Sleep(100);
}
}

if (story.currentChoices.Count == 0 && keepOpenAfterStoryFinish) {
Expand Down

0 comments on commit da3d4df

Please sign in to comment.