sharpgl icon indicating copy to clipboard operation
sharpgl copied to clipboard

WPF: animation freezes (see Teapot sample) if mouse is moving over window

Open alariq opened this issue 7 years ago • 4 comments

Not sure if SharpGL related, but this happens. Any way to fix this?

alariq avatar Jan 24 '18 14:01 alariq

Hi! The problem is that the priority of the Dispatcher that's responsible for the drawing is not set in the constructor of the control under 'timer = new DispatcherTimer()' in OpenGLControl.xaml.cs, The default constructor put the DispatcherPriority.Background in the priority which is lower than DispatcherPriority.Input (mouse movement). Simply change the initialization of the DispatcherTimer timer in the constructor of the control and put the priority manually. (There's a constructor that get a priority) rebuild and use the rebuilt version.

libritium avatar Oct 29 '18 14:10 libritium

Not relevant anymore but thanks anyway, maybe will be helpful for others

alariq avatar Oct 30 '18 19:10 alariq

I agree that the issue is the dispatchtimer as Librium said, but if I'm using this library from nuget, and not from this source, I don't have access to change the dispatch timer.

Is it possible instead to use System.Timers.Timer, and then use: Application.Current.Dispatcher.BeginInvoke( this._dispatcherPriority, new Action(() => { put rendering action here }));

Then expose the _dispatcherPriority field via a public property of the usercontrol?

JamesLear92 avatar Feb 10 '19 14:02 JamesLear92

In case anyone has this issue still and doesnt want to rebuild the source, you can overwrite the private field using reflection

var prop = openGLControl.GetType().GetField("timer",
    System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
prop.SetValue(openGLControl, new DispatcherTimer(DispatcherPriority.Render));

DarkDestry avatar Aug 01 '20 15:08 DarkDestry