Archived

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

strange message

This topic is 5113 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 programmers, I am having the following message in the Output: First-chance exception in test.exe (KERNEL32.DLL): 0xC0000005: Access Violation. Please, is there a known cause for this message? Thanks.

Share this post


Link to post
Share on other sites
This message typically happens when a program messes around with pointers that are not initialized. Overwriting bounds, or messing with memory that you should not be messin with.

Much more i'm sure, but you will have to more specific of what your doing.

[edited by - pjcast on December 15, 2003 12:08:56 AM]

Share this post


Link to post
Share on other sites
Place a breakpoint on the first line of your program. Now run it. After your breakpoint hits, show the output window. Now step through your program until you see the access violation occur while its in debug. Then post the line which is causing the error and all the variables going into it.

Share this post


Link to post
Share on other sites
Hi JoeyBlow2, sorry by the delay.

OK, I isolated the problem. The message appears due to these first 5 code lines, when I specify a path to a textures folder.

// Caminho para as texturas
const TCHAR *strPre = TEXT("C:/Programacao/Texturas/");
const int lenPre = lstrlen(strPre);
TCHAR caminho[MAX_PATH];
lstrcpyn(caminho,strPre,MAX_PATH);
lstrcpyn(caminho+ lenPre,matMaterials.pTextureFilename,MAX_PATH - lenPre);

// Criando a textura
if( FAILED( D3DXCreateTextureFromFileEx(
DispositivoD3D,
caminho,
D3DX_DEFAULT,
D3DX_DEFAULT,
5,
NULL,
D3DFMT_UNKNOWN,
D3DPOOL_MANAGED,
D3DX_FILTER_TRIANGLE ,
D3DX_DEFAULT,
0xff000000,
NULL,
NULL,
&Texturas[i] )))
{
Texturas[i] = NULL;
}

Share this post


Link to post
Share on other sites


const TCHAR *strPre = TEXT("C:/Programacao/Texturas/");
const int lenPre = lstrlen(strPre);
TCHAR caminho[MAX_PATH];
lstrcpyn(caminho,strPre,MAX_PATH);
lstrcpyn(caminho+ lenPre,matMaterials.pTextureFilename,MAX_PATH - lenPre);



I''m pretty sure its from the 4th line. You are telling it to copy MAX_PATH number of characters from strPre. However, strPre is a dynamic string, its not the same size as MAX_PATH. This is likely to cause an access violation. I''d change the code to be:



const TCHAR *strPre = TEXT("C:/Programacao/Texturas/");

TCHAR caminho[MAX_PATH];

lstrcpy(caminho,strPre);
lstrcat(caminho,matMaterials.pTextureFilename);



Just make sure that MAX_PATH is always going to be greater than the length of strPre + pTextureFilename, otherwise you''ll run into the same problem in reverse.

Share this post


Link to post
Share on other sites
Oh... the problem was stupid... sorry. I already fixed it.
In the past all my meshes were completely "textured" and the message didn''t appear. Now, some of my meshes have subsets with no texture (only material), and I just forgot to check if matMaterials.pTextureFilename always exist. So the problem appears when it tries to execute the 5th line.

I also will change the 4th and 5th line as JoeyBlow2 advised me.

Thanks for your attention and patience.

Share this post


Link to post
Share on other sites