使用DirectX 9时,Visual Studio 2013在Memset功能中提供了异常。 [英] Visual Studio 2013 Gives Exceptions at Memset function while using DirectX 9.

查看:87
本文介绍了使用DirectX 9时,Visual Studio 2013在Memset功能中提供了异常。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题从来没有回答过我。我刚刚阅读了使用Direct3D编程RTS游戏,当我编译第16章的代码以查看是否一切正常时,memset函数一直给我错误。当我注释掉memset
函数时,一切正常,但是memset绘制的东西,迷你地图,只是绘制方式的1/3。

This question was never answered for me. I just read Programming a RTS Game with Direct3D, and when I compiled the code for the 16th chapter to see if everything was working correctly, a memset function kept giving me errors. When I commented out the memset function, everything worked correctly, but the thing that the memset was drawing, the minimap, was only being 1/3 of the way drawn.

我在这里尝试了给我的解决方案:  https://social.msdn.microsoft.com/Forums/vstudio/en-US/88873be7-3d91-40d3-92dc- 2df4af2e0088 / visual-studio-2013-givesexceptions-at-memset-function-while-using-directx-9?forum = vcgeneral。

I tried the solution given to me here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/88873be7-3d91-40d3-92dc-2df4af2e0088/visual-studio-2013-givesexceptions-at-memset-function-while-using-directx-9?forum=vcgeneral.

此解决方案的结果允许memset函数为执行,但它只会消耗小地图的1/3。

The outcome of this solution allowed the memset function to be executed, but it would only draw 1/3 of the minimap still.

原始功能如下:

memset(bytes, 0, sRect.Pitch * sRect.Pitch);

给我的解决方案功能是:

the solution function that was given to me was this:

memset(bytes, 0, sRect.Pitch* 64);

注释掉原文并键入第二个memset函数具有相同的效果:小地图只会获得绘制方式的1/3。 

Commenting out the original and typing out the second memset function had the same effect: the minimap would only get 1/3 of the way drawn. 

以下是整个小地图功能:

Here is the whole minimap function:

void LoadMapObjectResources(IDirect3DDevice9* m_pDevice)
{
	D3DXCreateLine(m_pDevice, &line);

	D3DXCreateSprite(m_pDevice, &m_pSprite1);
	
	//Sight texture
	m_pDevice->CreateTexture(64, 64, 1, D3DUSAGE_DYNAMIC, D3DFMT_L8, D3DPOOL_DEFAULT, &sightTexture, NULL);

	D3DLOCKED_RECT sRect;
	sightTexture->LockRect(0, &sRect, NULL, NULL);
	BYTE *bytes = (BYTE*)sRect.pBits;
	
	memset(bytes, 0, sRect.Pitch* 64);
	
	float intensity = 1.3f;
	D3DXVECTOR2 center = D3DXVECTOR2(32.0f, 32.0f);
	
	for(int y=0;y<64;y++)
		for(int x=0;x<64;x++)
		{						
			float d = D3DXVec2Length(&(center - D3DXVECTOR2((float)x, (float)y)));
			int value = (int)(((32.0f - d) / 32.0f) * 255.0f * intensity);
			if(value < 0)value = 0;
			if(value > 255)value = 255;
			bytes[x + y * sRect.Pitch]  = value;
		}
	sightTexture->UnlockRect(0);

	//D3DXSaveTextureToFile("sightTexture.bmp", D3DXIFF_BMP, sightTexture, NULL);
	
	//Calculate sight mesh (a simple quad)
	D3DXCreateMeshFVF(2, 4, D3DXMESH_MANAGED, SIGHTVertex::FVF, m_pDevice, &sightMesh);

	//D3DXCreateSprite(m_pDevice, &m_pSprite);


	//D3DXCreateTextureFromFile(m_pDevice, "textures/SelectedWindow.dds", &selectedMenuTexture);
	D3DXCreateTextureFromFile(m_pDevice, "textures/SelectedWindow.dds", &selectedMenuTexture);
	//Create 4 vertices
	SIGHTVertex* v = 0;
	sightMesh->LockVertexBuffer(0,(void**)&v);
	v[0] = SIGHTVertex(D3DXVECTOR3(-1, 0, 1),  
        D3DXVECTOR2(0, 0));
	v[1] = SIGHTVertex(D3DXVECTOR3( 1, 0, 1),  
        D3DXVECTOR2(1, 0));
	v[2] = SIGHTVertex(D3DXVECTOR3(-1, 0, -1), 
        D3DXVECTOR2(0, 1));
	v[3] = SIGHTVertex(D3DXVECTOR3( 1, 0, -1), 
        D3DXVECTOR2(1, 1));
	sightMesh->UnlockVertexBuffer();

	//Create 2 faces
	WORD* indices = 0;
	sightMesh->LockIndexBuffer(0,(void**)&indices);	
	indices[0] = 0; indices[1] = 1; indices[2] = 2;
	indices[3] = 1; indices[4] = 3; indices[5] = 2;
	sightMesh->UnlockIndexBuffer();

	//Set Attributes for the 2 faces
	DWORD *att = 0;
	sightMesh->LockAttributeBuffer(0,&att);
	att[0] = 0; att[1] = 0;
	sightMesh->UnlockAttributeBuffer();

	//Sight MTRL
	memset(&sightMtrl, 0, sizeof(D3DMATERIAL9));
	sightMtrl.Diffuse = sightMtrl.Ambient = 
        D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);

	//Selected Effect
	selectedEffect = new 
        EFFECT_SELECTED(m_pDevice);
}

我能否找到解决此问题的实际答案?我已经给出了可能给出问题的整个区域。

Can I get an actual answer that will fix this issue? I have given the whole area that could be giving issues.

推荐答案

如果在memset调用中减少length参数允许函数执行没有错误,那么你的原始长度参数很可能导致memset尝试写入你不拥有的内存。

If reducing the length argument in the call to memset allows the function to execute without error, then it is very likely that your original length argument caused memset to attempt to write to memory you don't own.

memset 仅用零填充指定的区域。 &NBSP;它没有绘制任何东西。

memset merely populates the specified area with zeros.  It doesn't draw anything.

DirectX.9的一个特点是绘制的数量取决于所绘制的数据而不是控制结构中的信息? 如果你根本不打电话给memset会发生什么?  如果用长度参数的不同
值调用它,图形有何不同?

Is it a feature of DirectX.9 that the amount drawn depends on the data being drawn rather than information in a control structure?  What happens if you don't call memset at all?  How does the drawing differ if you call it with different values for the length argument?


这篇关于使用DirectX 9时,Visual Studio 2013在Memset功能中提供了异常。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆