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 3147 - Windows: Crash when resizing Window since hg 333216331863
Summary: Windows: Crash when resizing Window since hg 333216331863
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.1
Hardware: x86 Windows 8
: P2 major
Assignee: David Ludwig
QA Contact: David Ludwig
URL:
Keywords:
: 3370 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-10-11 12:12 UTC by Gab
Modified: 2016-06-25 02:20 UTC (History)
5 users (show)

See Also:


Attachments
Should fix the issue (584 bytes, patch)
2016-01-13 22:44 UTC, Gab
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gab 2015-10-11 12:12:13 UTC
SDL_renderer_d3d.c line 844

if (!texture->texture) {
    return 0;
}

texture is NULL and crashes.

How to reproduce: Create a Window with SDL_WINDOW_RESIZABLE and resize it.

The first bad revision is 333216331863

https://hg.libsdl.org/SDL/rev/333216331863

"Use D3D9Ex when available
 This hopefully works around crashes in Intel D3D9 support in Windows 8.1."

Stacktrace:
Playerd.exe!D3D_RecreateTextureRep(IDirect3DDevice9 * device, D3D_TextureRep * texture, unsigned int format, int w, int h) Zeile 844	C
Playerd.exe!D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) Zeile 969	C
Playerd.exe!D3D_Reset(SDL_Renderer * renderer) Zeile 419	C
Playerd.exe!D3D_ActivateRenderer(SDL_Renderer * renderer) Zeile 474	C
Playerd.exe!D3D_RenderClear(SDL_Renderer * renderer) Zeile 1232	C
Playerd.exe!SDL_RenderClear(SDL_Renderer * renderer) Zeile 1354	C
Playerd.exe!SdlUi::UpdateDisplay() Zeile 543	C++
[...]
Comment 1 Gab 2015-10-11 12:14:38 UTC
Oh and this crashes with both Intel and Nvidia for me. Both have up-to-date drivers.
Comment 2 David Ludwig 2015-12-29 16:36:38 UTC
Hi Gab,

I'm unable to reproduce this on any of my Windows systems, and I'm not sure why.  I created a window with SDL_WINDOW_RESIZABLE set, but was able to resize it without crashing, both with and without textures on it.

Do you have any additional details on the system(s) you used to test this on?

Any chance you could provide a sample program?
Comment 3 Gab 2015-12-29 19:32:59 UTC
Thanks for the update, I will recheck. Maybe got fixed in the meanwhile.
Comment 4 David Ludwig 2015-12-30 19:22:12 UTC
I'm also unable to reproduce this using the revision you mentioned, https://hg.libsdl.org/SDL/rev/333216331863.

Gab, might you have code for a small, sample program, which I could use to try reproducing this?
Comment 5 Gab 2016-01-12 19:59:21 UTC
Sorry, was my fault. I'm using the DirectX February 2010 SDK for compiling (since years) and just read on MSDN that they ship the DX SDK now with the Windows SDK... So removing that include fixed the crash.
Comment 6 David Ludwig 2016-01-12 20:02:22 UTC
Got it.  Thanks for the updated info!
Comment 7 Gab 2016-01-13 22:06:06 UTC
I'm sorry, have to reopen. I encountered the crash again and figured out the real cause now by stepping through SDL code.

The SDL_Texture must be created with a SDL_TEXTURE_FORMAT that is not supported (returns false for "IsSupportedFormat", for me this is SDL_PIXELFORMAT_ABGR8888)

This results in two textures being created (one in unsupported format, one in supported format) and only the supported one gets the "driverdata" field assigned (makes sense because only the supported one can be used by DirectX).

But D3D_Reset just loops over all textures and passes them to D3D_RecreateTexture which accesses driverdata but does not check for NULL.

The DirectX 11 backend has a NULL check in D3D11_DestroyTexture:

D3D11_TextureData *data = (D3D11_TextureData *)texture->driverdata;

if (!data) {
    return;
}
Comment 8 Gab 2016-01-13 22:44:09 UTC
Created attachment 2364 [details]
Should fix the issue

Proposed patch.

The alternative codepath through D3D_DestroyTexture already checks for NULL btw ;)
Comment 9 Stephen E. Baker 2016-04-07 00:47:12 UTC
Confirmed that the patch fixed this crash for us. In our case the issue occurred when we were targeting larger than screen resolutions.
Comment 10 Kai Sterker 2016-06-22 19:09:23 UTC
*** Bug 3370 has been marked as a duplicate of this bug. ***
Comment 11 David Ludwig 2016-06-25 02:20:23 UTC
Fix applied via https://hg.libsdl.org/SDL/rev/17e0ded12e6f

Thanks for the fix, Gab!