Archived

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

kapru

Access Violation

Recommended Posts

kapru    100
Im making a texture blending routien but im getting an error ill hilight the line that causes the error
CFrameWorkApplication::CPUTextureBlender()
{
	//Obtain the final textures surface

	int i,j,count,scale;
	int col;

    D3DLOCKED_RECT TextureLR;
	unsigned int *TextureBits;
	unsigned int TexturePitch;
	D3DSURFACE_DESC TextureDesc;

    D3DLOCKED_RECT SourceTextureLR[4];
	unsigned int *SourceTextureBits[4];
	unsigned int SourceTexturePitch[4];
	D3DSURFACE_DESC SourceTextureDesc[4];

	terrRenderTarget->GetLevelDesc(0, &TextureDesc);
	terrRenderTarget->LockRect( 0, &TextureLR, 0, 0 );
	TextureBits=(unsigned int*)TextureLR.pBits;
	TexturePitch=TextureLR.Pitch/4;
	//get the source textures surface

	for(i=0;i<4;i++)
	{
		terrTexture[i]->GetLevelDesc(0, &SourceTextureDesc[i]);
		terrTexture[i]->LockRect( 0, &SourceTextureLR[i], 0, 0 );
		SourceTextureBits[i]=(unsigned int*)SourceTextureLR[i].pBits;
		SourceTexturePitch[i]=TextureLR.Pitch/4;
	}
	
	scale = rendertargetsize/(terrSizeX*blendmapscale);

	//Split this part up for testing purposes

	//Cycle throught the blend maps and apply the parts that are 255

	for(count=0;count<4;count++)
	{
	for(i=0;i<(int)TextureDesc.Width;i++)
		for(j=0;j<(int)TextureDesc.Height;j++)
		{
			if(i<rendertargetsize&&j<rendertargetsize)
			{
				//read the valuse out of the height map

				//if its 255 then plot it on the rendertarget

				if(BlendMap[count][(j/scale)*(terrSizeX*blendmapscale)+(i/scale)]==255)
				{
					//get the colour from the source texture and put it on the

					//render target

					//col=D3DCOLOR_ARGB(255,0,255,0);//((DWORD*)SourceTextureLR.pBits)[count][SourceTextureDesc[count].Width*j+i];

***********************************************************
	                TextureBits[TextureDesc.Width*j+i] =0;//D3DCOLOR_ARGB(255,0,255,0);

***********************************************************
				}
			}
		}
	}
	terrRenderTarget->UnlockRect(0);
	terrTexture[0]->UnlockRect(0);
	terrTexture[1]->UnlockRect(0);
	terrTexture[2]->UnlockRect(0);
	terrTexture[3]->UnlockRect(0);

}

Share this post


Link to post
Share on other sites
UdayK    122
Make sure the textures you are trying to lock are actually getting locked. Do a SUCCEEDED() or a FAILED() check.

This line:
terrRenderTarget->LockRect( 0, &TextureLR, 0, 0 );

Like, for example, it could fail if you are trying to lock a texture that was created with D3DPOOL_DEFAULT.

Share this post


Link to post
Share on other sites
DrunkenHyena    805
You also seem to be ignoring the pitch of the texture, that''s not a good thing to do.

This tutorial covers locking and editing a texture:
http://www.drunkenhyena.com/docs/d3d_tutorial.phtml#DHComputedAlpha


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites