Jump to content
  • Advertisement
Sign in to follow this  
conciliator

Passing NULL to

This topic is 3062 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've seen that D3DXVECTOR3 * D3DXVec3Normalize(D3DXVECTOR3 * pOut, CONST D3DXVECTOR3 * pV); and similar functions returns "the same value returned in the pOut parameter. In this way, the D3DXVec3Normalize function can be used as a parameter for another function." (from documentation). Does this mean that I'm allowed to pass a NULL pointer as pOut? It feels a little bad to do it, but sure would be convenient... :) Are there any official guidelines for using such functions as parameters for other functions, as indicated by the documentation?

Share this post


Link to post
Share on other sites
Advertisement
I'm almost positive that you would not be allowed to do that. The D3DXVec3Normalize function would try to dereference a NULL pointer, thus creating a segmentation fault. Now maybe I am incorrect, and thet actually coded that functionality into the function, but it could all be cleared up by a simple test on your end.

[Edited by - Halifax2 on February 28, 2010 3:09:19 AM]

Share this post


Link to post
Share on other sites
Sounds like they are describing:
D3DXVec3Normalize( &foo, &foo ) == &foo

So the return is the same pointer you passed in as pOut, so you can nest your calls like
add( out, add( out, x, y ), z )

Share this post


Link to post
Share on other sites
I always assumed that was the way it was meant to work. Given the lack of a definitive answer right now, why not just try and see?

Share this post


Link to post
Share on other sites
Thanks guys, I thought I'd already tested it and it ran fine. However, going through my code once more, I realized the function was never called. And guess what: I got (as expected) an access violation writing to 0x000000.

The reason I asked in the first place, was that it seemed to work fine. This was so surprising to me that I wanted to check with the community before starting to use it all over the place. In the end, its not such a big deal. At least I learned something. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!