From: Connor McAdams cmcadams@codeweavers.com
Fixes a crash in Just Cause 2, which loads a DDS file with a flags value of DDS_PF_ALPHA | DDS_PF_FOURCC.
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/d3dx_helpers.c | 8 ++++++-- dlls/d3dx9_36/tests/surface.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/dlls/d3dx9_36/d3dx_helpers.c b/dlls/d3dx9_36/d3dx_helpers.c index 4c70a328e40..2033bcb9653 100644 --- a/dlls/d3dx9_36/d3dx_helpers.c +++ b/dlls/d3dx9_36/d3dx_helpers.c @@ -289,6 +289,7 @@ static BOOL dds_pixel_format_compare(const struct dds_pixel_format *pf_a, const
static enum d3dx_pixel_format_id d3dx_pixel_format_id_from_dds_pixel_format(const struct dds_pixel_format *pixel_format) { + DWORD flags = pixel_format->flags; uint32_t i;
TRACE("pixel_format: size %lu, flags %#lx, fourcc %#lx, bpp %lu.\n", pixel_format->size, @@ -296,14 +297,17 @@ static enum d3dx_pixel_format_id d3dx_pixel_format_id_from_dds_pixel_format(cons TRACE("rmask %#lx, gmask %#lx, bmask %#lx, amask %#lx.\n", pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
+ /* DDS_PF_FOURCC overrides all other flags. */ + if (flags & DDS_PF_FOURCC) + flags = DDS_PF_FOURCC; for (i = 0; i < ARRAY_SIZE(dds_pixel_formats); ++i) { const struct dds_pixel_format *dds_pf = &dds_pixel_formats[i].dds_pixel_format;
- if (pixel_format->flags != dds_pf->flags) + if (flags != dds_pf->flags) continue;
- switch (pixel_format->flags & ~DDS_PF_ALPHA) + switch (flags & ~DDS_PF_ALPHA) { case DDS_PF_ALPHA_ONLY: if (dds_pixel_format_compare(pixel_format, dds_pf, FALSE, FALSE, FALSE, TRUE)) diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index f8d20efdbb8..60281d3480c 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -259,7 +259,7 @@ static void check_dds_pixel_format_image_info(unsigned int line, dds.header.pixel_format.bmask = bmask; dds.header.pixel_format.amask = amask; hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info); - todo_wine_if(flags == ~0u) ok_(__FILE__, line)(hr == expected_hr, "Unexpected hr %#lx.\n", hr); + ok_(__FILE__, line)(hr == expected_hr, "Unexpected hr %#lx.\n", hr); if (SUCCEEDED(hr) && hr == expected_hr) ok_(__FILE__, line)(info.Format == expected_format, "Unexpected format %#x.\n", info.Format); }