mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-10 19:25:39 +00:00
[OpenTK] Do not hang when update rate too high
OpenTK will now detect when an UpdateFrame handler is consistently taking too long to finish, and stop raising UpdateFrame events. This gives ProcessEvents() a chance to execute and will protect the application from hanging up.
This commit is contained in:
parent
95d71bc0cc
commit
1f44cf27a1
|
@ -92,6 +92,8 @@ namespace OpenTK
|
|||
|
||||
double update_epsilon; // quantization error for UpdateFrame events
|
||||
|
||||
bool is_running_slowly; // true, when UpdatePeriod cannot reach TargetUpdatePeriod
|
||||
|
||||
VSyncMode vsync;
|
||||
|
||||
FrameEventArgs update_args = new FrameEventArgs();
|
||||
|
@ -440,6 +442,7 @@ namespace OpenTK
|
|||
|
||||
void DispatchUpdateAndRenderFrame(object sender, EventArgs e)
|
||||
{
|
||||
int is_running_slowly_retries = 4;
|
||||
double timestamp = watch.Elapsed.TotalSeconds;
|
||||
double elapsed = 0;
|
||||
|
||||
|
@ -464,6 +467,14 @@ namespace OpenTK
|
|||
// per ProcessEvents() call)
|
||||
break;
|
||||
}
|
||||
|
||||
is_running_slowly = update_epsilon >= TargetUpdatePeriod;
|
||||
if (is_running_slowly && --is_running_slowly_retries == 0)
|
||||
{
|
||||
// If UpdateFrame consistently takes longer than TargetUpdateFrame
|
||||
// stop raising events to avoid hanging inside the UpdateFrame loop.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
elapsed = ClampElapsed(timestamp - render_timestamp);
|
||||
|
|
Loading…
Reference in a new issue