We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4792

Summary: SDL app becomes unresponsive when the Windows RDP is connected/disconnected?
Product: SDL Reporter: superfury
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: 2.0.10   
Hardware: Other   
OS: Linux   

Description superfury 2019-09-06 21:26:20 UTC
I notice that when I connect or disconnect using RDP, the entire SDL2 app becomes unresponsive(stops updating video completely, audio not tested). Currently on vanilla 2.0.10.
Comment 1 superfury 2019-09-07 09:36:26 UTC
Just confirmed it's happening on the latest SDL2 hg commit as well.

Also tried Dosbox, which isn't affected and uses SDL 1.2
Comment 2 superfury 2019-09-07 10:13:31 UTC
That Dosbox version uses 1.2.13.0, according to it's metadata.

Trying to run my app using 2.0.9 has no effect either: it still doesn't update it's input anymore.
Comment 3 superfury 2019-09-07 10:35:32 UTC
Just tried stepping through the SDL rendering functions. I see something VERY strange: no render present is done anymore! At src/render/direct3d/SDL_render_d3d.c line 1505 it always returns after RDP connect/disconnect, without rendering anymore(line 1512, the call to IDirect3DDevice9_Present is never reached anymore)!
Comment 4 superfury 2019-09-07 11:03:26 UTC
So the following code is at fault here:

static void
D3D_RenderPresent(SDL_Renderer * renderer)
{
    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
    HRESULT result;

    if (!data->beginScene) {
        IDirect3DDevice9_EndScene(data->device);
        data->beginScene = SDL_TRUE;
    }

    result = IDirect3DDevice9_TestCooperativeLevel(data->device);
    if (result == D3DERR_DEVICELOST) {
        /* We'll reset later */
        return;
    }

That 'We'll reset later' is always reached from the point it connects and disconnects! That never changes anymore! So IDirect3DDevice9_TestCooperativeLevel

I also see the other place that resets, is never reached!

Just tried adding:
		data->updateSize = SDL_TRUE; //Trigger a reset later!

At the "We'll reset later" location to trigger the reset at line , but that makes the renderer only give more errors later on?
Comment 5 superfury 2019-09-07 11:04:55 UTC
It was to trigger the reset at line 317.
Comment 6 superfury 2019-09-07 18:13:53 UTC
I just found out that switching to fullscreen under RDP(which fails completely switching to it), then switching back to windowed mode seems to 'fix' the issue until the next (dis)connect of RDP.

In my app's case that destroys textures and all window-related objects(SDL_DestroyRenderer, SDL_DestroyTexture etc.), then creates them again in the specified windowed or fullscreen mode.
Comment 7 superfury 2019-09-08 12:00:57 UTC
OK. Some more testing confirmed the following:
- When the app reloads all SDL 1.2-compatible rendering stuff(see the 1.2 migration guide on the SDL2 docs) but the window that's createn(preserving the window itself), the rendering continues properly(this now also happens when my app detects a RDP session being started or terminated(also on fullscreen toggling or window resolution changing)).
- The Microsoft RDP detection doesn't work properly (from https://docs.microsoft.com/en-us/windows/win32/termserv/detecting-the-terminal-services-environment , the function at the bottom of the page). When my app is started it detects correctly, but when it's running, it doesn't see RDP disconnect(already disconnected actually) until the user is logged in at the computer itself(running the latest Windows 10 updates, normal update channel). So either logging in using another RDP-like service(like TeamViewer) or actually logging in on the computer itself physically/locally(using the connected keyboard and mouse on usb/ps2 ports) will make the function start returning that RDP is disconnected.

So that's a problem in Windows 10 itself? My app (when that RDP detection is working properly) will keep refreshing the screen properly only when the RDP detection works properly. I can force it to toggle RDP or refresh in two ways:
1. Disconnect RDP(undetected), connect using TeamViewer(which makes the app see that RDP 'disconnected', thus refreshing the required textures etc.), disconnect Teamviewer(no changes), finally connecting Mictosoft RDP again(which toggles RDP back on for the app, thus refreshing textures).
2. Toggle fullscreen(where fullscreen stops ALL RDP rendering, including the desktop, making the RDP session screen capture freeze/stop updating) on and off.

So it's now completely a Windows 10 issue?