Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions Core/Libraries/Source/WWVegas/WW3D2/missingtexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,18 @@ void MissingTexture::_Init()
DX8_ErrorCode(tex->UnlockRect(0));

for (unsigned i=1;i<tex->GetLevelCount();++i) {
IDirect3DSurface8 *src,*dst;
DX8_ErrorCode(tex->GetSurfaceLevel(i-1,&src));
DX8_ErrorCode(tex->GetSurfaceLevel(i,&dst));
IDirect3DSurface8 *src = nullptr;
IDirect3DSurface8 *dst = nullptr;
HRESULT hr_src = tex->GetSurfaceLevel(i-1,&src);
HRESULT hr_dst = tex->GetSurfaceLevel(i,&dst);

// Validate both GetSurfaceLevel calls succeeded and surfaces are valid
if (FAILED(hr_src) || src == nullptr || FAILED(hr_dst) || dst == nullptr) {
WWDEBUG_SAY(("Error: GetSurfaceLevel failed or returned NULL surface in MissingTexture::_Init"));
if (src != nullptr) src->Release();
if (dst != nullptr) dst->Release();
continue;
}

DX8_ErrorCode(D3DXLoadSurfaceFromSurface(
dst,
Expand Down
23 changes: 22 additions & 1 deletion Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,13 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture
{
DX8_THREAD_ASSERT();
DX8_Assert();

// Validate surface parameter
if (surface == nullptr) {
WWDEBUG_SAY(("Error: NULL surface passed to _Create_DX8_Texture"));
return MissingTexture::_Get_Missing_Texture();
}

IDirect3DTexture8 *texture = nullptr;

D3DSURFACE_DESC surface_desc;
Expand All @@ -2398,10 +2405,24 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture
// not in a supported texture format.
WW3DFormat format=D3DFormat_To_WW3DFormat(surface_desc.Format);
texture = _Create_DX8_Texture(surface_desc.Width, surface_desc.Height, format, mip_level_count);

// Validate texture was created successfully
if (texture == nullptr) {
WWDEBUG_SAY(("Error: Failed to create texture in _Create_DX8_Texture"));
return MissingTexture::_Get_Missing_Texture();
}

// Copy the surface to the texture
IDirect3DSurface8 *tex_surface = nullptr;
texture->GetSurfaceLevel(0, &tex_surface);
HRESULT hr = texture->GetSurfaceLevel(0, &tex_surface);

// Validate GetSurfaceLevel succeeded and tex_surface is valid
if (FAILED(hr) || tex_surface == nullptr) {
WWDEBUG_SAY(("Error: GetSurfaceLevel failed or returned NULL surface in _Create_DX8_Texture"));
texture->Release();
return MissingTexture::_Get_Missing_Texture();
}

DX8_ErrorCode(D3DXLoadSurfaceFromSurface(tex_surface, nullptr, nullptr, surface, nullptr, nullptr, D3DX_FILTER_BOX, 0));
tex_surface->Release();

Expand Down
23 changes: 22 additions & 1 deletion GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2646,6 +2646,13 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture
{
DX8_THREAD_ASSERT();
DX8_Assert();

// Validate surface parameter
if (surface == nullptr) {
WWDEBUG_SAY(("Error: NULL surface passed to _Create_DX8_Texture"));
return MissingTexture::_Get_Missing_Texture();
}

IDirect3DTexture8 *texture = nullptr;

D3DSURFACE_DESC surface_desc;
Expand All @@ -2656,10 +2663,24 @@ IDirect3DTexture8 * DX8Wrapper::_Create_DX8_Texture
// not in a supported texture format.
WW3DFormat format=D3DFormat_To_WW3DFormat(surface_desc.Format);
texture = _Create_DX8_Texture(surface_desc.Width, surface_desc.Height, format, mip_level_count);

// Validate texture was created successfully
if (texture == nullptr) {
WWDEBUG_SAY(("Error: Failed to create texture in _Create_DX8_Texture"));
return MissingTexture::_Get_Missing_Texture();
}

// Copy the surface to the texture
IDirect3DSurface8 *tex_surface = nullptr;
texture->GetSurfaceLevel(0, &tex_surface);
HRESULT hr = texture->GetSurfaceLevel(0, &tex_surface);

// Validate GetSurfaceLevel succeeded and tex_surface is valid
if (FAILED(hr) || tex_surface == nullptr) {
WWDEBUG_SAY(("Error: GetSurfaceLevel failed or returned NULL surface in _Create_DX8_Texture"));
texture->Release();
return MissingTexture::_Get_Missing_Texture();
}

DX8_ErrorCode(D3DXLoadSurfaceFromSurface(tex_surface, nullptr, nullptr, surface, nullptr, nullptr, D3DX_FILTER_BOX, 0));
tex_surface->Release();

Expand Down
Loading