Skip to content
Merged
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
37 changes: 35 additions & 2 deletions Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,17 @@ Render2DSentenceClass::Allocate_New_Surface (const WCHAR *text, bool justCalcExt
//
CurSurface = NEW_REF (SurfaceClass, (CurrTextureSize, CurrTextureSize, WW3D_FORMAT_A4R4G4B4));
WWASSERT (CurSurface != NULL);

//
// Validate that the underlying D3D surface was successfully created
//
if (CurSurface != NULL && !CurSurface->Is_Valid()) {
// Surface creation failed - clean up and return
REF_PTR_RELEASE(CurSurface);
CurSurface = NULL;
return;
}

CurSurface->Add_Ref ();

//
Expand Down Expand Up @@ -931,7 +942,15 @@ void Render2DSentenceClass::Build_Sentence_Centered (const WCHAR *text, int *hkX
//
if (LockedPtr == NULL) {
LockedPtr = (uint16 *)CurSurface->Lock (&LockedStride);
WWASSERT (LockedPtr != NULL);
// If Lock() failed (returned NULL), we cannot render text - abort gracefully
if (LockedPtr == NULL) {
// Stop processing - cannot continue without a valid surface
if(hkX)
*hkX = hotKeyPosX;
if(hkX)
*hkY = hotKeyPosY;
return;
}
}

//
Expand Down Expand Up @@ -1121,7 +1140,21 @@ Vector2 Render2DSentenceClass::Build_Sentence_Not_Centered (const WCHAR *text, i
{
if (LockedPtr == NULL) {
LockedPtr = (uint16 *)CurSurface->Lock (&LockedStride);
WWASSERT (LockedPtr != NULL);
// If Lock() failed (returned NULL), we cannot render text - abort gracefully
if (LockedPtr == NULL) {
// Return the extent we've calculated so far
Vector2 extent;
extent.X = maxX + Font->Get_Extra_Overlap();
extent.Y = Cursor.Y + char_height;
Cursor = cursor;
TextureOffset = textureOffset;
TextureStartX = textureStartX;
if(hkX)
*hkX = hotKeyPosX;
if(hkX)
*hkY = hotKeyPosY;
return extent;
}
}
}

Expand Down
87 changes: 87 additions & 0 deletions Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ SurfaceClass::~SurfaceClass(void)

void SurfaceClass::Get_Description(SurfaceDescription &surface_desc)
{
// Check if the D3D surface is valid before attempting to get description
if (D3DSurface == NULL) {
surface_desc.Format = WW3D_FORMAT_UNKNOWN;
surface_desc.Height = 0;
surface_desc.Width = 0;
return;
}

D3DSURFACE_DESC d3d_desc;
::ZeroMemory(&d3d_desc, sizeof(D3DSURFACE_DESC));
DX8_ErrorCode(D3DSurface->GetDesc(&d3d_desc));
Expand All @@ -259,6 +267,12 @@ void SurfaceClass::Get_Description(SurfaceDescription &surface_desc)

void * SurfaceClass::Lock(int * pitch)
{
// Check if the D3D surface is valid before attempting to lock
if (D3DSurface == NULL) {
if (pitch) *pitch = 0;
return NULL;
}

D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));
DX8_ErrorCode(D3DSurface->LockRect(&lock_rect, 0, 0));
Expand All @@ -268,6 +282,10 @@ void * SurfaceClass::Lock(int * pitch)

void SurfaceClass::Unlock(void)
{
// Check if the D3D surface is valid before attempting to unlock
if (D3DSurface == NULL) {
return;
}
DX8_ErrorCode(D3DSurface->UnlockRect());
}

Expand All @@ -288,6 +306,11 @@ void SurfaceClass::Unlock(void)
*=============================================================================================*/
void SurfaceClass::Clear()
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -327,6 +350,11 @@ void SurfaceClass::Clear()
*=============================================================================================*/
void SurfaceClass::Copy(const unsigned char *other)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -366,6 +394,11 @@ void SurfaceClass::Copy(const unsigned char *other)
*=============================================================================================*/
void SurfaceClass::Copy(Vector2i &min,Vector2i &max, const unsigned char *other)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -411,6 +444,14 @@ void SurfaceClass::Copy(Vector2i &min,Vector2i &max, const unsigned char *other)
*=============================================================================================*/
unsigned char *SurfaceClass::CreateCopy(int *width,int *height,int*size,bool flip)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
*width = 0;
*height = 0;
*size = 0;
return NULL;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -472,6 +513,11 @@ void SurfaceClass::Copy(
WWASSERT(width);
WWASSERT(height);

// Check if either D3D surface is invalid
if (D3DSurface == NULL || other->D3DSurface == NULL) {
return;
}

SurfaceDescription sd,osd;
Get_Description(sd);
const_cast <SurfaceClass*>(other)->Get_Description(osd);
Expand Down Expand Up @@ -529,6 +575,11 @@ void SurfaceClass::Stretch_Copy(
{
WWASSERT(other);

// Check if either D3D surface is invalid
if (D3DSurface == NULL || other->D3DSurface == NULL) {
return;
}

SurfaceDescription sd,osd;
Get_Description(sd);
const_cast <SurfaceClass*>(other)->Get_Description(osd);
Expand Down Expand Up @@ -565,6 +616,11 @@ void SurfaceClass::Stretch_Copy(
*=============================================================================================*/
void SurfaceClass::FindBB(Vector2i *min,Vector2i*max)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -640,6 +696,11 @@ void SurfaceClass::FindBB(Vector2i *min,Vector2i*max)
*=============================================================================================*/
bool SurfaceClass::Is_Transparent_Column(unsigned int column)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return true;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -708,6 +769,12 @@ bool SurfaceClass::Is_Transparent_Column(unsigned int column)
*=============================================================================================*/
void SurfaceClass::Get_Pixel(Vector3 &rgb, int x,int y)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
rgb.Set(0, 0, 0);
return;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -805,6 +872,11 @@ void SurfaceClass::Detach (void)
*=============================================================================================*/
void SurfaceClass::DrawPixel(const unsigned int x,const unsigned int y, unsigned int color)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -859,6 +931,11 @@ void SurfaceClass::DrawPixel(const unsigned int x,const unsigned int y, unsigned
*=============================================================================================*/
void SurfaceClass::DrawHLine(const unsigned int y,const unsigned int x1, const unsigned int x2, unsigned int color)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return;
}

SurfaceDescription sd;
Get_Description(sd);

Expand Down Expand Up @@ -918,6 +995,11 @@ void SurfaceClass::DrawHLine(const unsigned int y,const unsigned int x1, const u
*=============================================================================================*/
bool SurfaceClass::Is_Monochrome(void)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return false;
}

unsigned int x,y;
SurfaceDescription sd;
Get_Description(sd);
Expand Down Expand Up @@ -1008,6 +1090,11 @@ bool SurfaceClass::Is_Monochrome(void)
*=============================================================================================*/
void SurfaceClass::Hue_Shift(const Vector3 &hsv_shift)
{
// Check if the D3D surface is valid
if (D3DSurface == NULL) {
return;
}

unsigned int x,y;
SurfaceDescription sd;
Get_Description(sd);
Expand Down
3 changes: 3 additions & 0 deletions Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ class SurfaceClass : public W3DMPO, public RefCountClass

WW3DFormat Get_Surface_Format() const { return SurfaceFormat; }

// Check if the underlying D3D surface is valid
bool Is_Valid() const { return D3DSurface != NULL; }

private:

// Direct3D surface object
Expand Down
Loading