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

application freeze on niceDCV resize desktop operation #133

Open
flat-eric147 opened this issue Jul 26, 2024 · 5 comments
Open

application freeze on niceDCV resize desktop operation #133

flat-eric147 opened this issue Jul 26, 2024 · 5 comments

Comments

@flat-eric147
Copy link

I am having an interesting issue to report. I am using OpenTK within a windows WPF application. It works perfectly fine and I am doing very basic OpenGL stuff in there (mainly visualizing a videostream).
I encountered an issue when using my application on an AWS instance using niceDCV. niceDCV has a feature where you can resize the windows and it does resize the "remote" desktop accordingly (that behaviour can be switched off however).
My application starts to freeze whenever this kind of operation takes place. I managed to create a stack trace and it mostly looks like this:

System.Threading.WaitHandle.WaitOneNoCheck(Int32)
System.Windows.Interop.D3DImage.LockImpl(System.Windows.Duration)
System.Windows.Interop.D3DImage.Lock()
OpenTK.Wpf.GLWpfControlRenderer.Render(System.Windows.Media.DrawingContext)
OpenTK.Wpf.GLWpfControl.OnRender(System.Windows.Media.DrawingContext)
System.Windows.UIElement.Arrange(System.Windows.Rect)
System.Windows.ContextLayoutManager.UpdateLayout()
System.Windows.ContextLayoutManager.UpdateLayoutCallback(System.Object)
[...]
I am a little bit lost on how to further debug or fix this issue. It "feels" like some d3d handle got disposed without OpenTK's knowledge. Any input/hint appreciated !

@flat-eric147
Copy link
Author

I ran a minimal sample project on the target machine building the GLwpfControl on my own in debug, when running and resizing the desktop I get the following stack trace:

PresentationCore.dll!System.Windows.Media.Composition.DUCE.Channel.SyncFlush() Line 220 C#
PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowSettings(bool enableRenderTarget, System.Windows.Media.Composition.DUCE.ChannelSet? channelSet) Line 1321 C#
PresentationCore.dll!System.Windows.Interop.HwndTarget.UpdateWindowPos(nint lParam) Line 1215 C#
PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage msg, nint wparam, nint lparam) Line 770 C#
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(nint hwnd, int msg, nint wParam, nint lParam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
PresentationFramework.dll!System.Windows.Window.UpdateHwndPositionOnTopLeftChange(double leftLogicalUnits, double topLogicalUnits) Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) Unknown
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) Unknown
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal) Unknown
WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) Unknown
Microsoft.VisualStudio.DesignTools.WpfTap.dll!Microsoft.VisualStudio.DesignTools.WpfTap.WpfVisualTreeService.Adorners.AdornerWindow.UpdatePlacement() Unknown
Microsoft.VisualStudio.DesignTools.WpfTap.dll!Microsoft.VisualStudio.DesignTools.WpfTap.Utility.DispatcherUtility.SafeInvokeAsync.AnonymousMethod__0() Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeDelegateCore() Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Unknown
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 138 C#
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(nint hwnd, int msg, nint wParam, nint lParam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Unknown
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Unknown
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Unknown
testOpengl.dll!testOpengl.App.Main() Unknown

crashopentk

The code looks like this (just played with various settings for Profile, ContextFlag and versions but they don't change a thing):

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

    var settings = new GLWpfControlSettings
     {
         MajorVersion = 3,
         MinorVersion = 3,
         RenderContinuously = true,
         Profile = OpenTK.Windowing.Common.ContextProfile.Compatability,
         ContextFlags = OpenTK.Windowing.Common.ContextFlags.Offscreen
     };
     OpenTkControl.Start(settings);
 }

 private float col = 0;
 private void OpenTkControl_OnRender(TimeSpan delta)
 {
     col = (col + 0.01f) % 1;
     GL.ClearColor(col, 1, 1, 1);

     GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 }

}

@flat-eric147
Copy link
Author

And another update... Sorry for all the noise. But maybe it helps the desperate soul. On the server side of Nice DCV the option "IDD Driver" needs to be disabled.
disable_idd
https://www.ni-sp.com/support/nice-dcv-tips-and-tricks/#h-how-to-disable-the-windows-idd-driver-in-nice-dcv
Once that's disable everything runs fine when resizing the nicedcv window.

@NogginBops
Copy link
Member

This feels like we want to investigate why it is happening and if there is some way for us to support this. I'm guessing the crash is because the IDD driver does some resize operation while our code doesn't expect it..
I'll reopen this issue just to see if I can figure something out, if I don't I'll close the issue.

@NogginBops NogginBops reopened this Jul 27, 2024
@flat-eric147
Copy link
Author

Hi, happy to help and test this. The resizing works fine without IDD. I closed this since it felt like a very rare use case.

@NogginBops
Copy link
Member

NogginBops commented Jul 27, 2024

It might be a very rare use case, but it would be good to know why it happens and if any other software causes the same issue.

(oops I managed to close the issue, reopened again)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants