IOS- fixed crash on first tick
FrameEventArgs throws an exception when setting the Time to a value <= 0. With that knowledge, both the Android and the IOS implementations had a bug when setting the time. On IOS, that bug would cause a crash on the first tick, as the first tick would always set to 0. On Android the bug was probably harmless but there was a redundant check there (and also removed the unneeded allocation that was there on every tick).
This commit is contained in:
parent
fe9e300e09
commit
2b15ae3700
2 changed files with 12 additions and 14 deletions
|
@ -493,8 +493,8 @@ namespace OpenTK.Platform.Android
|
||||||
DateTime prevRenderTime;
|
DateTime prevRenderTime;
|
||||||
DateTime curUpdateTime;
|
DateTime curUpdateTime;
|
||||||
DateTime curRenderTime;
|
DateTime curRenderTime;
|
||||||
FrameEventArgs updateEventArgs;
|
FrameEventArgs updateEventArgs = new FrameEventArgs();
|
||||||
FrameEventArgs renderEventArgs;
|
FrameEventArgs renderEventArgs = new FrameEventArgs();
|
||||||
|
|
||||||
// this method is called on the main thread if RenderOnUIThread is true
|
// this method is called on the main thread if RenderOnUIThread is true
|
||||||
void RunIteration (CancellationToken token)
|
void RunIteration (CancellationToken token)
|
||||||
|
@ -505,21 +505,19 @@ namespace OpenTK.Platform.Android
|
||||||
if (!ReadyToRender)
|
if (!ReadyToRender)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
updateEventArgs = new FrameEventArgs ();
|
|
||||||
curUpdateTime = DateTime.Now;
|
curUpdateTime = DateTime.Now;
|
||||||
if (prevUpdateTime.Ticks != 0) {
|
if (prevUpdateTime.Ticks != 0) {
|
||||||
var t = (curUpdateTime - prevUpdateTime).TotalSeconds;
|
var t = (curUpdateTime - prevUpdateTime).TotalSeconds;
|
||||||
updateEventArgs.Time = t < 0 ? 0 : t;
|
updateEventArgs.Time = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateFrameInternal (updateEventArgs);
|
UpdateFrameInternal (updateEventArgs);
|
||||||
prevUpdateTime = curUpdateTime;
|
prevUpdateTime = curUpdateTime;
|
||||||
|
|
||||||
renderEventArgs = new FrameEventArgs ();
|
|
||||||
curRenderTime = DateTime.Now;
|
curRenderTime = DateTime.Now;
|
||||||
if (prevRenderTime.Ticks == 0) {
|
if (prevRenderTime.Ticks == 0) {
|
||||||
var t = (curRenderTime - prevRenderTime).TotalSeconds;
|
var t = (curRenderTime - prevRenderTime).TotalSeconds;
|
||||||
renderEventArgs.Time = t < 0 ? 0 : t;
|
renderEventArgs.Time = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderFrameInternal (renderEventArgs);
|
RenderFrameInternal (renderEventArgs);
|
||||||
|
|
|
@ -861,20 +861,20 @@ namespace OpenTK.Platform.iPhoneOS
|
||||||
internal void RunIteration (NSTimer timer)
|
internal void RunIteration (NSTimer timer)
|
||||||
{
|
{
|
||||||
var curUpdateTime = stopwatch.Elapsed;
|
var curUpdateTime = stopwatch.Elapsed;
|
||||||
if (prevUpdateTime == TimeSpan.Zero)
|
if (prevUpdateTime.Ticks != 0) {
|
||||||
prevUpdateTime = curUpdateTime;
|
|
||||||
var t = (curUpdateTime - prevUpdateTime).TotalSeconds;
|
var t = (curUpdateTime - prevUpdateTime).TotalSeconds;
|
||||||
updateEventArgs.Time = t;
|
updateEventArgs.Time = t;
|
||||||
|
}
|
||||||
OnUpdateFrame(updateEventArgs);
|
OnUpdateFrame(updateEventArgs);
|
||||||
prevUpdateTime = curUpdateTime;
|
prevUpdateTime = curUpdateTime;
|
||||||
|
|
||||||
gl.BindFramebuffer(All.FramebufferOes, framebuffer);
|
gl.BindFramebuffer(All.FramebufferOes, framebuffer);
|
||||||
|
|
||||||
var curRenderTime = stopwatch.Elapsed;
|
var curRenderTime = stopwatch.Elapsed;
|
||||||
if (prevRenderTime == TimeSpan.Zero)
|
if (prevRenderTime.Ticks == 0) {
|
||||||
prevRenderTime = curRenderTime;
|
var t = (curRenderTime - prevRenderTime).TotalSeconds;
|
||||||
t = (curRenderTime - prevRenderTime).TotalSeconds;
|
|
||||||
renderEventArgs.Time = t;
|
renderEventArgs.Time = t;
|
||||||
|
}
|
||||||
OnRenderFrame(renderEventArgs);
|
OnRenderFrame(renderEventArgs);
|
||||||
prevRenderTime = curRenderTime;
|
prevRenderTime = curRenderTime;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue