Sign in to follow this  

SetMaterial(NULL) causing crash

This topic is 3593 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

I'm using lighting and materials in my game, and for some of the object's I'm I don't want materials applied to them. I tried using m_Device->SetMaterial(NULL), where m_Device is a valid IDirect3DDevice*, and it crashes with an access violation error. After it crashed, I tried the same call using a valid material, and it didn't crash, but it also didn't give me the results I want. Is there anything wrong with calling SetMaterial and passing in NULL, or is there a better way to not apply materials to specific objects?

Share this post


Link to post
Share on other sites
I don't think setting a NULL material really makes much sense. If the material is NULL, what's Direct3D going to use for its lighting calculations?

If you want to disable lighting, use SetRenderState() instead.

Share this post


Link to post
Share on other sites
NULL isn't a valid parameter for SetMaterial().

1. The debug D3D runtime would have told you that ("Direct3D9: (ERROR) :Invalid D3DMATERIAL pointer. SetMaterial failed."). The debug runtime is a great tool for debugging D3D problems.


2. What behaviour do you expect from setting a NULL material? A D3DMATERIAL9 with all elements set to 0 (black)? A D3DMATERIAL9 with all elements set to 1 (white)? A D3DMATERIAL9 with the diffuse or ambient set to white and specular set to black? No lighting computation?

If you want to disable lighting entirely, set the D3DRS_LIGHTING render state to FALSE. If the effect you want is just the texture colour rather than the lit texture colour, then you'll need to change the D3DTSS_COLOROP texture stage state to select whichever argument the texture is in instead of modulating between them.

An alternative is to set up a new material with the ambient values set to white and the rest set to black then set the D3DRS_AMBIENT render state to white.


Share this post


Link to post
Share on other sites
And if you're trying to use vertex colors for lighting, set D3DRS_COLORVERTEX to TRUE. Set D3DRS_DIFFUSEMATERIALSOURCE to D3DMCS_COLOR1 and possibly D3DRS_SPECULARMATERIALSOURCE to D3DMCS_COLOR2. Maybe you want ambient to use your diffuse vertex color too. If so, set D3DRS_AMBIENTMATERIALSOURCE to D3DMCS_COLOR1.

Share this post


Link to post
Share on other sites

This topic is 3593 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this