Jump to content
  • Advertisement

Archived

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

okonomiyaki

Passing by reference. Why didn't this work?

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

Last night was one of those nights where I was banging my head against the wall for hours until I found the small unexpected bug in my program. I have an object class that calls a GetTexCoords() function in another class. Originally the function was defined as this:
void vertexStripper::GetTexCoords(float &u, float &v, vec2 vPos) {
  u = vPos.x/(dataSize-1);
  v = vPos.y/(dataSize-1);
}
However, tracing through my program shows that u or v sometimes does not get set correctly (looks like the garbage value you get when you declare a value without initializing). Half the time they did get set correctly. I changed it to this, and to my surprise, it worked:
float vertexStripper::GetTexCoordU(vec2 vPos) {
  return vPos.x/(dataSize-1);
}
float vertexStripper::GetTexCoordV(vec2 vPos) {
  return vPos.y/(dataSize-1);
}
Is there any reason why the first method should not have worked?? Maybe there is a bug elsewhere *shrugs*

Share this post


Link to post
Share on other sites
Advertisement
what is the copy constructor for vec2?
What type are the members x and y?
Are they initialised?
If they are not fundamental types have you defined operator/ for them?
is datasize == 1?
is datasize initialised?

these are all places that there could be bugs although I doubt them all. clutching at straws.

Share this post


Link to post
Share on other sites
Yeah, tracing through the program shows all of those places to be fine. x, y area floats, dataSize is an int that is always 257 (for now).
The main argument against all of that is that the second method works, which involves the same kind of operations. The only difference is that I'm not passing by reference, but explicitly saying vert[ i ].u = GetTexCoordU(vPos). Same for V value.
Who knows *shrugs* I've seen worse.

Thanks though!

edit: auto-formatted wrong

[edited by - okonomiyaki on May 27, 2004 11:19:21 AM]

Share this post


Link to post
Share on other sites
How did you call the original function? It looks like it should work fine. Try adding printf''s at the start and end of the function.

Share this post


Link to post
Share on other sites

  • 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!