DXGL r350 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r349‎ | r350 | r351 >
Date:15:46, 17 March 2013
Author:admin
Status:new
Tags:
Comment:
Trace glDirect3DLight.cpp and fix invalid object return value.
Modified paths:
  • /ddraw/glDirect3DLight.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DLight.cpp
@@ -28,6 +28,7 @@
2929
3030 glDirect3DLight::glDirect3DLight()
3131 {
 32+ TRACE_ENTER(1,14,this);
3233 refcount=1;
3334 viewport = NULL;
3435 device = NULL;
@@ -35,66 +36,85 @@
3637 light.dltType = D3DLIGHT_DIRECTIONAL;
3738 light.dcvAmbient.r = light.dcvAmbient.g = light.dcvAmbient.b = 1.0f;
3839 light.dvDirection = D3DVECTOR(0,0,1.0);
 40+ TRACE_EXIT(-1,0);
3941 }
4042 glDirect3DLight::glDirect3DLight(D3DLIGHT7 *light_in)
4143 {
 44+ TRACE_ENTER(2,14,this,14,light_in);
4245 refcount=1;
4346 memcpy(&light,light_in,sizeof(D3DLIGHT7));
 47+ TRACE_EXIT(-1,0);
4448 }
4549
4650 glDirect3DLight::~glDirect3DLight()
4751 {
 52+ TRACE_ENTER(1,14,this);
 53+ TRACE_EXIT(-1,0);
4854 }
4955
5056 ULONG WINAPI glDirect3DLight::AddRef()
5157 {
52 - if(!this) return 0;
 58+ TRACE_ENTER(1,14,this);
 59+ if(!this) TRACE_RET(8,0);
5360 refcount++;
 61+ TRACE_EXIT(8,refcount);
5462 return refcount;
5563 }
5664 ULONG WINAPI glDirect3DLight::Release()
5765 {
58 - if(!this) return 0;
 66+ TRACE_ENTER(1,14,this);
 67+ if(!this) TRACE_RET(8,0);
5968 ULONG ret;
6069 refcount--;
6170 ret = refcount;
6271 if(refcount == 0) delete this;
 72+ TRACE_EXIT(8,ret);
6373 return ret;
6474 }
6575
6676 HRESULT WINAPI glDirect3DLight::Initialize(LPDIRECT3D lpDirect3D)
6777 {
68 - if(!this) return DDERR_INVALIDPARAMS;
 78+ TRACE_ENTER(2,14,this,14,lpDirect3D);
 79+ if(!this) TRACE_RET(23,DDERR_INVALIDOBJECT);
 80+ TRACE_EXIT(23,DDERR_ALREADYINITIALIZED);
6981 return DDERR_ALREADYINITIALIZED;
7082 }
7183
7284 HRESULT WINAPI glDirect3DLight::QueryInterface(REFIID riid, void** ppvObj)
73 -{
74 - if(!this) return DDERR_INVALIDPARAMS;
75 - if(!ppvObj) return DDERR_INVALIDPARAMS;
 85+{TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
 86+ if(!this) TRACE_RET(23,DDERR_INVALIDOBJECT);
 87+ if(!ppvObj) TRACE_RET(23,DDERR_INVALIDPARAMS);
7688 if(riid == IID_IUnknown)
7789 {
7890 this->AddRef();
7991 *ppvObj = this;
 92+ TRACE_VAR("*ppvObj",14,*ppvObj);
 93+ TRACE_EXIT(23,D3D_OK);
8094 return D3D_OK;
8195 }
 96+ TRACE_EXIT(23,E_NOINTERFACE);
8297 return E_NOINTERFACE;
8398 }
8499
85100 void glDirect3DLight::GetLight7(LPD3DLIGHT7 lpLight7)
86101 {
 102+ TRACE_ENTER(2,14,this,14,lpLight7);
87103 memcpy(lpLight7,&light,sizeof(D3DLIGHT7));
 104+ TRACE_EXIT(0,0);
88105 }
89106 void glDirect3DLight::SetLight7(LPD3DLIGHT7 lpLight7)
90107 {
 108+ TRACE_ENTER(2,14,this,14,lpLight7);
91109 memcpy(&light,lpLight7,sizeof(D3DLIGHT7));
 110+ TRACE_EXIT(0,0);
92111 }
93112
94113 HRESULT WINAPI glDirect3DLight::GetLight(LPD3DLIGHT lpLight)
95114 {
96 - if(!this) return DDERR_INVALIDPARAMS;
97 - if(!lpLight) return DDERR_INVALIDPARAMS;
98 - if(lpLight->dwSize < sizeof(D3DLIGHT)) return DDERR_INVALIDPARAMS;
 115+ TRACE_ENTER(2,14,this,14,lpLight);
 116+ if(!this) TRACE_RET(23,DDERR_INVALIDOBJECT);
 117+ if(!lpLight) TRACE_RET(23,DDERR_INVALIDPARAMS);
 118+ if(lpLight->dwSize < sizeof(D3DLIGHT)) TRACE_RET(23,DDERR_INVALIDPARAMS);
99119 lpLight->dltType = light.dltType;
100120 lpLight->dcvColor = light.dcvDiffuse;
101121 lpLight->dvPosition = light.dvPosition;
@@ -106,13 +126,15 @@
107127 lpLight->dvAttenuation2 = light.dvAttenuation2;
108128 lpLight->dvTheta = light.dvTheta;
109129 lpLight->dvPhi = light.dvPhi;
 130+ TRACE_EXIT(23,D3D_OK);
110131 return D3D_OK;
111132 }
112133 HRESULT WINAPI glDirect3DLight::SetLight(LPD3DLIGHT lpLight)
113134 {
114 - if(!this) return DDERR_INVALIDPARAMS;
115 - if(!lpLight) return DDERR_INVALIDPARAMS;
116 - if(lpLight->dwSize < sizeof(D3DLIGHT)) return DDERR_INVALIDPARAMS;
 135+ TRACE_ENTER(2,14,this,14,lpLight);
 136+ if(!this) TRACE_RET(23,DDERR_INVALIDOBJECT);
 137+ if(!lpLight) TRACE_RET(23,DDERR_INVALIDPARAMS);
 138+ if(lpLight->dwSize < sizeof(D3DLIGHT)) TRACE_RET(23,DDERR_INVALIDPARAMS);
117139 light.dltType = lpLight->dltType;
118140 light.dcvDiffuse = lpLight->dcvColor;
119141 light.dcvAmbient.r = light.dcvAmbient.g = light.dcvAmbient.b = light.dcvAmbient.a = 0;
@@ -137,18 +159,27 @@
138160 }
139161 else device->LightEnable(index,FALSE);
140162 }
 163+ TRACE_EXIT(23,D3D_OK);
141164 return D3D_OK;
142165 }
143166
144167 void glDirect3DLight::SetDevice(glDirect3DDevice7 *device, int index)
145168 {
 169+ TRACE_ENTER(3,14,this,14,device,11,index);
146170 this->device = device;
147171 this->index = index;
 172+ TRACE_EXIT(0,0);
148173 }
149174
150175 void glDirect3DLight::Sync()
151176 {
152 - if(!this) return;
 177+ TRACE_ENTER(1,14,this);
 178+ if(!this)
 179+ {
 180+ TRACE_EXIT(0,0);
 181+ return;
 182+ }
153183 device->SetLight(index,&light);
154184 device->LightEnable(index,TRUE);
 185+ TRACE_EXIT(0,0);
155186 }
\ No newline at end of file