ofMap returning nan or inf

I have some code which is relying on ofMap to slide a large image back and forth.

there seems to be an odd error coming from this, however.

legitWidth = imageWidth - ofGetWidth();
position = ofMap(cX,0,640,0,-legitWidth);

imageWidth is greater than getWidth();
cX = position of person (in front of kinect) found using openCV.

for some reason the values I get for position will sometimes be inf or NaN…

If I could ‘check’ for these instances I could assign an alternative in both cases, but unfortunately I don’t seem to be able to. It just gets these values and… doesn’t crash, just sits there until something let’s it generate a real value.

Right after this instance I check for >0 or <legitWidth instances, but it never gets there if it is NaN or inf…

This is using 0.8.1

could you print the values before and after the ofMap?
So many people has been using this method that is hard to think that there is something wrong with it… so I guess that the NaN/inf is comming from somewhere else… but i could be wrong…

try to do a good print. It will make things easier

… er… “print?”…


that sounds splendiferous, or something…

… how do I do that?

Maybe I didn’t explain myself well. ofMap has been around for a while and I doubt there is something wrong with it. I suggest you could output to the console all the values before and after ofMap so that you can make sure if it is really ofMap the one causing the problem.
If the problem is still there make a simple example so that someone can help you looking at the code.

@nosarious You can print stuff to the console with ofLog. For example:

ofLog() << someVariable;

It sounds like one of the variable you’re putting into ofMap() is NaN or infinity, which can cause the output to be NaN / infinity as well. This is normal c++ behaviour.

I found the answer a while ago (sorry I didn’t respond)

I had to rewrite my code a bit to understand the spaghetti nature (my usual process is: “code, test, curse, repeat”) I was down to using recipe cards and laying it out on a rug to understand it fully. (it didn’t “seem” that complicated when I was making it)

The problem has been resolved, but I am not sure how. Thank you very much for your help.