الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مالخطأ في هذا الكود

بدأه 852147 في 27 يوليو 2008 · 9 رد · 2,406 مشاهدة · في DirectX
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

أولا السلام عليكم لدي نص هذ الكود

if (SUCCEEDED (direct3d->CheckDeviceType ( D3DADAPTER_DEFAULT , D3DDEVTYPE_HAL , 
										  D3DFMT_A32B32G32R32F , D3DFMT_A32B32G32R32F   , TRUE )))
	{
		FormatType = D3DFMT_A32B32G32R32F; 


	}

أثنائ بويلد المشروع لايظهر أي خطأ

ولكن عندما أنفذه تظهر علبة حوار وتخبرني بأنه يوجد خطأ وهذه العلبة بها زرين

break and continue

فما هي المشكلة

تم تعديل هذه المشاركة بواسطة 852147 في 27 يوليو 2008 في 11:57

#2

السلام عليكم

أخي الكريم

لدي بعض التعليق ربما يساعدك في حل المشكلة

دائما افحص قيمة ال HRESULT التي ترجعها الدالة لتعرف بصورة اكثر دقة الخطأ الذي حدث

هذه الدالة تحاول معرفة هل يمكن وضع ال device في ال Format الممرر للدالة بال device type الممرر ايضا

الان هناك بعض الامور التي لابد من اخذها في الاعتبار عند استخدامك للدالة CheckDeviceType

هناك مصطلحان لابد ان تفهم الفرق بينهم جيدا

------------------------------------------------------------------------------------------------------

الاول هو ال Adapter Fromat or Front Format or Display Fromat

وهو ال Format الذي سنضع ال Adapter فيه

لدينا هنا حالتين فقط:

1- في حالة ال Windowed mode

لابد ان تكون قيمة format adapter هي نفسها المستخدمة حاليا في ال desktop mode ولمعرفتها يمكنك استخدام الدالة

GetDisplayMode

2- في حالة ال Full-Screen mode

فقط يمكن وضع ال adapter في احدي هذه ال fromats

D3DFMT_X1R5G5B5

D3DFMT_R5G6B5

D3DFMT_X8R8G8B8

---------------------------------------------------------------------------------------------------------------------------

الثاني: هو ال Back Buffer or frame buffer وهو ال fromat الذي نريد وضع ال device فيه ولدينا حالتين:

1- في حالة Windowed mode

يمكن اختيار احدي ال formats الاتية

D3DFMT_X1R5G5B5

D3DFMT_R5G6B5

D3DFMT_X8R8G8B8

D3DFMT_A8R8G8B8

D3DFMT_A1R5G5B5

D3DFMT_A2R10G10B10

2- في حالة ال Full-Screen mode

يمكن فقط استخدام Format يناظر تقريبا القيمة المختارة للـ Front Buffer

For fullscreen devices, the formats and resolutions must match, with one exception: the back buffer

can still have an alpha channel even though the physical display does not. The rule is that the alpha

mode must match the non-alpha mode counterpart (with the placeholder ‘X’ value). If we set the

display mode of the adapter to 32 bit, the front buffer format will be D3DFMT_X8R8G8B8. This means

we can have a back buffer format of either D3DFMT_X8R8G8B8 or D3DFMT_A8R8G8B8. Likewise,

if we

were in 16 bit mode D3DFMT_X1R5G5B5, we could create a back buffer in either D3DFMT_X1R5G5B5 or

D3DFMT_A1R5G5B5

.

اتمني ان تتبع ما ذكر وان شاء الله تتحل المشكلة

تم تعديل هذه المشاركة بواسطة aeamg2005 في 27 يوليو 2008 في 12:50

Ahmed Ezz

Software Engineer

ezzelden.ahmed@yahoo.com

http://ahmedezz.110mb.com/

انما عمرك بأعمالك ، فكم تريد أن تعيش؟

#3

شكراعلى الشرح ممكن

شرح الدالة GetDisplayMode وبالأمثلة

#4

السلام عليكم

للتسهيل يمكن استخدام الدالة GetAdapterDisplayMode لاسترجاع ال Display ,mode المستخدم حاليا كالاتي

bool CGameApp::InitDirect3D()
{
	// here we gonna create our d3d object along with device object

	D3DPRESENT_PARAMETERS PresentParams;
	D3DCAPS9			  Caps;
	/*
	The D3DDISPLAYMODE structure will be used to obtain and store the display
	mode currently being used by the primary adapter to display the Windows desktop. 
	*/
	D3DDISPLAYMODE		  CurrentMode;
	HRESULT				  hRet;

	/*
	we attempt to create the Direct3D9 object.  If successful,
	the returned pointer to an IDirect3D9 interface is stored in the CGameApp class
	member variable m_pD3D. If the call is unsuccessful and m_pD3D is NULL,
	then something is terribly wrong and the application cannot continue.
	This is likely the result of incorrect (or non-existent) installation of DirectX.
	*/
	// First of all create our D3D Object 
	m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ); 
	if (!m_pD3D)  return false;

	/*
	we will fill out the  D3DPRESENT_PARAMETERS structure in preparation for passing
	it to the IDirect3D9::CreateDevice function. For the most part,
	environment setup is no more complicated than figuring out the correct values
	to  store in this structure and then passing it into the CreateDevice function.
	Just to be safe, the first thing we do is zero out the structure.
	*/
	// Fill out a simple set of present parameters 
	ZeroMemory( &PresentParams, sizeof(D3DPRESENT_PARAMETERS) ); 

	/*
	we use the IDirect3D9::GetAdapterMode function and pass it the address of
	a D3DISPLAYMODE. The function will fill this structure with the current adapter
	display mode. We have specified the D3DADAPTER_DEFAULT flag which means that
	we are asking for the current display mode of the primary adapter.  

	We store the pixel format of the returned display mode in the 
	BackBufferFormat member of the D3DPRESENT_PAREMETERS structure.
	This informs the device  that we want a frame buffer with a matching pixel format.
	*/
	// select backbuffer format
	m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &CurrentMode);
	PresentParams.BackBufferFormat = CurrentMode.Format;

	// set remaining flags
	/*
	we need to use and attatch a depthbuffer at device creating time, so
	we call our defined func that will return a valid depth-bufer format
	supported by this device
	*/
	PresentParams.EnableAutoDepthStencil = true;
	/*
	get the best valid depth format that is supported by current passed display mode
	for the current adapter that we will need it in HAL device type
	*/
	PresentParams.AutoDepthStencilFormat = 
		FindDepthStencilFormat(D3DADAPTER_DEFAULT, CurrentMode, D3DDEVTYPE_HAL);

	// let the device choose the best presentation approach for the swap-effect
	PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
	// enable windowed mode
	PresentParams.Windowed = true;

	// the overall remaining flags can be set to default values by the device

	// now to check for this card capabilites to perform lighting and transformation
	// in hardware

	// Set Device Creating Flags
	unsigned long ulFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;   // default

	// check if hardware T&L is avaialble
	ZeroMemory(&Caps, sizeof(D3DCAPS9));

	m_pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &Caps);
	if(Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
		ulFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;

	/*
	The IDirect3D9::GetDeviceCaps above  returns a D3DCAPS9 structure.
	It contains the functionality and capabilities of a particular device type
	on a particular adapter. This structure is quite large and you can examine
	its members in the SDK documentation. We will cover many of its members throughout
	this course as our application hardware requirements grow and checking for
	capabilities becomes more important. In the code we are asking for the capabilities
	structure for the HAL device on the primary adapter. If the HAL device supports
	transformation and lighting in hardware as well as rasterization, the DevCaps
	member of the D3DCAPS9 structure will have the D3DDEVCAPS_HWTRANSFORMANDLIGHT 
	flag set. If this flag is not set then either the HAL only supports rasterization
	(in which case we must create the device using the 
	D3DCREATE_SOFTWARE_VERTEXPROCESSING flag) or a HAL device is not present on the
	hardware. We will now try to create a device. We pass the adapter ordinal we wish
	to create the device for (D3DADPATER_DEFAULT), the device type we wish to create
	(a HAL device), the HWND of the focus window (created in the CreateDisplay
	function  and also used as the device window by default), the vertex processing
	we wish the device to use, the address of the presentation parameters structure
	that we filled in above, and the address of  a pointer to an  IDirect3DDevice9 
	interface that will be filled in if the call is successful.
	*/

	// attempt to create a HAL device
	if(FAILED(hRet = m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
									m_hWnd, ulFlags, &PresentParams, &m_pD3DDevice)))
	{
		/*
		If device creation fails, we will try to create a HEL device
		(reference rasterizer). If this is the case, we should amend the 
		AutoDepthStencilFormat field with a depth surface pixel format that 
		is compatible with the REF device. We call our helper function again
		to test depth buffer formats for the reference rasterizer and return
		the best supported format:  
		*/
		// Find REF depth buffer format
		PresentParams.AutoDepthStencilFormat = 
			FindDepthStencilFormat(D3DADAPTER_DEFAULT, CurrentMode, D3DDEVTYPE_REF);

		// check if T&L is exist in this hardware
		ZeroMemory(&Caps, sizeof(D3DCAPS9));
		ulFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
		m_pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, &Caps);
		if(Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
			ulFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;

		// attempt to create a REF device
		// Attempt to create a REF device 
		if( FAILED( hRet = m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, m_hWnd, 
											   ulFlags, &PresentParams, &m_pD3DDevice ) ) )  
		{ 
			// Failed 
			return false;		 
		} // End if Failure (REF)
	} // End if Failure (HAL) 

	/*
	If the reference device could not be created, then  something is terribly wrong
	and we will have no choice but to exit the application with an error.
	If our device is successfully created, then we store the presentation parameters
	so that we can access them later if need be.
	*/
	m_D3DPresentParams = PresentParams;

	// success
	return true;
}

اتمني ان يفيدك هذا المثال

تم تعديل هذه المشاركة بواسطة aeamg2005 في 27 يوليو 2008 في 15:17

Ahmed Ezz

Software Engineer

ezzelden.ahmed@yahoo.com

http://ahmedezz.110mb.com/

انما عمرك بأعمالك ، فكم تريد أن تعيش؟

#5

ألف شكرا ياأخي شكرا علىالشرح

#6

قمت بما قلت لي حرفيا وظهر لي نفس الخطأ

الصور المرفقة توضح ذلك

MyErrore.rar

#7

حسنا اخي الكريم

اود لو ترفق المشروع لاستطيع تتبع المشكلة لان الصورة التي ارفقتها لا توضح مثلا حالة ال stack

وهي اشياء لا بد من معرفتها كذلك الخطأ يشير مبدئيا الي ان هناك unInitialized var

او انك تنتهك وتحاول القراءة في الذاكرة في مكان غير متاح لبرنامج وهناك اسباب عديدة للخطأ

في انتظار ارفاق الكود لاتابع معك ان شاء الله

Ahmed Ezz

Software Engineer

ezzelden.ahmed@yahoo.com

http://ahmedezz.110mb.com/

انما عمرك بأعمالك ، فكم تريد أن تعيش؟

#8

هذا هو المشروع ياأخي

MyClassDevice.rar

#9

السلام عليكم

الملفات المرفقة الان تعمل

test.rar

Ahmed Ezz

Software Engineer

ezzelden.ahmed@yahoo.com

http://ahmedezz.110mb.com/

انما عمرك بأعمالك ، فكم تريد أن تعيش؟

#10

شكرا

مواضيع مشابهة