Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

djoseph74

Not all paths returned...

This topic is 5217 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m running into an error: c:\documents and settings\dan joseph\my documents\visual studio projects\space invaders 3d\d3d_init.cpp(64): warning C4715: ''CD3D::CD3D_init'' : not all control paths return a value I''m using Visual Studio .NET 2003, C++.. I cannot for the life of my find what I''ve done wrong. Can someone point it out?
#include "d3d_init.h"

CD3D::CD3D()
{
	d3d_interface = NULL;
	d3d_device    = NULL;
}

bool CD3D::CD3D_init( HWND hwnd )
{
	int vp = 0;

	D3DDEVTYPE deviceType;

 	d3d_interface = Direct3DCreate9( D3D_SDK_VERSION );

	D3DCAPS9 si3D_caps;

	d3d_interface->GetDeviceCaps( D3DADAPTER_DEFAULT,      //Denotes primate display adapter.
								  deviceType,              // Specifies the device type, usually D3DDEVTYPE HAL.
								  &si3D_caps           );  // Return filled D3DCAPS9 structure that contains the capabilities of the primary display adapter.

	// If the bit is "on" then that implies the hardware device supports it.

	if ( si3D_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
	{
		// Yes, the bit is "on", so it is supported.

		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
	}
	else
	{
		// No, the bit is not "on", so it is not supported.

		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	}

	if ( d3d_interface == NULL )
		return false;

	D3DPRESENT_PARAMETERS si3D_params = {0};

	si3D_params.BackBufferFormat           = D3DFMT_A8R8G8B8;  // pixel format
	si3D_params.SwapEffect                 = D3DSWAPEFFECT_DISCARD;
	si3D_params.Windowed                   = true; // false = fullscreen ; true = windowed;

	HRESULT result = d3d_interface->CreateDevice( D3DADAPTER_DEFAULT,			// Primary Device
												  D3DDEVTYPE_HAL,				// device type, hal = hardware vertex proc, ref = software vertex proc
												  hwnd,							// window associated with the device
												  vp,							// vertex proc type (HAL/REF)
												  &si3D_params,					// present parameters
												  &d3d_device             );		// returned created device.

	if ( result == D3D_OK )
	{
		return true;		// Could initialize D3D successfully
	}
	else if ( result != D3D_OK )
	{
		return false;		// Coul dnot initialize D3D
	}
}
 

Share this post


Link to post
Share on other sites
Advertisement
Your problem is that your function is set to return a value, and it would theoretically be possible for it to run to the end without returning a value. Change your little block at the end to this:



if ( result == D3D_OK )
return true; // Could initialize D3D successfully

else
return false; // Coul dnot initialize D3D

Share this post


Link to post
Share on other sites
Ahh, I did not realize I could run through that with the scenario of not finding a match in the if''s... Thank you all for your input. I wll be more careful on stepping thru my code. Now if I can get a grasp on the D3D initialization, this will be a successful night...

-Dan Joseph

Share this post


Link to post
Share on other sites
quote:
Original post by djoseph74
Ahh, I did not realize I could run through that with the scenario of not finding a match in the if''s...



Technically it will never happen. But your compiler is not so smart that it can figure that out.

Share this post


Link to post
Share on other sites
I recommend you change your bool CD3D::Init into

HRESULT CD3D::Init;

and the return value can be S_OK or E_FAIL.

you can use if ( FAILED ( Init(hWnd) ) ) or

if ( SUCCEEDED ( Init(hWnd) ) )

to detect that your application runs OK.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!