Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@
//Figure out correct reduction
int reqReduction=WW3D::Get_Texture_Reduction(); //requested reduction

if (reqReduction >= mip_count)

Check warning on line 1329 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-debug+t+e

'>=': signed/unsigned mismatch

Check warning on line 1329 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32+t+e

'>=': signed/unsigned mismatch

Check warning on line 1329 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-debug+t+e

'>=': signed/unsigned mismatch

Check warning on line 1329 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-profile+t+e

'>=': signed/unsigned mismatch

Check warning on line 1329 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-profile+t+e

'>=': signed/unsigned mismatch

Check warning on line 1329 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32+t+e

'>=': signed/unsigned mismatch
reqReduction=mip_count-1; //leave only the lowest level

//Clamp reduction
Expand Down Expand Up @@ -1363,7 +1363,7 @@
//Figure out correct reduction
int reqReduction=WW3D::Get_Texture_Reduction(); //requested reduction

if (reqReduction >= mip_count)

Check warning on line 1366 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-debug+t+e

'>=': signed/unsigned mismatch

Check warning on line 1366 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32+t+e

'>=': signed/unsigned mismatch

Check warning on line 1366 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-debug+t+e

'>=': signed/unsigned mismatch

Check warning on line 1366 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-profile+t+e

'>=': signed/unsigned mismatch

Check warning on line 1366 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-profile+t+e

'>=': signed/unsigned mismatch

Check warning on line 1366 in Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32+t+e

'>=': signed/unsigned mismatch
reqReduction=mip_count-1; //leave only the lowest level

//Clamp reduction
Expand Down Expand Up @@ -1457,7 +1457,6 @@
Width = width;
Height = height;
Format = Get_Valid_Texture_Format(orig_format, Texture->Is_Compression_Allowed());
Reduction = reduction;


if (!Texture->Is_Reducible() || Texture->MipLevelCount == MIP_LEVELS_1)
Expand All @@ -1479,9 +1478,13 @@
// Otherwise take as many mip levels as the texture wants, not to exceed the count in file...
if (!mip_level_count)
{
reducedWidth >>= Reduction;
reducedHeight >>= Reduction;
mip_level_count = orig_mip_count-Reduction;//dds_file.Get_Mip_Level_Count();
if(reducedWidth !=4 && reducedHeight !=4)
{
reducedWidth >>= Reduction;
reducedHeight >>= Reduction;
mip_level_count = orig_mip_count-Reduction;//dds_file.Get_Mip_Level_Count();
}
Comment on lines +1481 to +1486
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The guard skips the whole block only when a dimension is exactly 4, but it still allows the bulk right-shift to produce values below 4 for wider dimensions. For example, if Width = 8 and Reduction = 2 (texture too large for hardware, needing two mip levels of reduction), the condition passes because 8 != 4, but reducedWidth >>= 2 yields 2 — below the DXT block minimum. Load_Compressed_Mipmap avoids this by reducing incrementally and breaking before going under 4, so a texture whose Width came out above 4 from the hardware-limit loop could end up with a D3D surface two bytes narrower than the data being copied into it. Clamping with std::max makes the intent explicit and aligns the two functions.

Suggested change
if(reducedWidth !=4 && reducedHeight !=4)
{
reducedWidth >>= Reduction;
reducedHeight >>= Reduction;
mip_level_count = orig_mip_count-Reduction;//dds_file.Get_Mip_Level_Count();
}
reducedWidth = max(4u, reducedWidth >> Reduction);
reducedHeight = max(4u, reducedHeight >> Reduction);
mip_level_count = orig_mip_count-Reduction;//dds_file.Get_Mip_Level_Count();
Prompt To Fix With AI
This is a comment left during a code review.
Path: Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp
Line: 1481-1486

Comment:
The guard skips the whole block only when a dimension is **exactly** 4, but it still allows the bulk right-shift to produce values below 4 for wider dimensions. For example, if `Width = 8` and `Reduction = 2` (texture too large for hardware, needing two mip levels of reduction), the condition passes because `8 != 4`, but `reducedWidth >>= 2` yields 2 — below the DXT block minimum. `Load_Compressed_Mipmap` avoids this by reducing incrementally and breaking before going under 4, so a texture whose `Width` came out above 4 from the hardware-limit loop could end up with a D3D surface two bytes narrower than the data being copied into it. Clamping with `std::max` makes the intent explicit and aligns the two functions.

```suggestion
		reducedWidth  = max(4u, reducedWidth  >> Reduction);
		reducedHeight = max(4u, reducedHeight >> Reduction);
		mip_level_count = orig_mip_count-Reduction;//dds_file.Get_Mip_Level_Count();
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Author

@Mr-Sheerlock Mr-Sheerlock Jun 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix would leave the binarystream texture with dimensions 4x4 which doesn't render. I agree that the logic might over-reduce though.


if (mip_level_count < 1)
mip_level_count = 1; //sanity check to make sure something gets loaded.
}
Expand Down Expand Up @@ -1835,6 +1838,7 @@

if (Reduction)
{ for (unsigned int level = 0; level < Reduction; ++level) {
if (height == 4 || width == 4) break;
width >>= 1;
height >>= 1;
}
Expand Down
Loading