Visual Studio 2013 Gives Exceptions at Memset function while using DirectX 9.

  • Thread starter Thread starter rydog1234567890
  • Start date Start date
R

rydog1234567890

Guest
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.


I tried the solution given to me here: Visual Studio 2013 GivesExceptions at Memset function while using DirectX 9..

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


the original function was this:

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



the solution function that was given to me was this:

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



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.

Continue reading...
 
Back
Top