473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

I think I broke C

2
I am student doing the typical ray tracer in C on Sun Sparc. One of the features is glossy reflections, where the reflected angle is slightly skewed a number of times depending on a variable, and the resulting color is averaged. The problem is, all the glossy reflections come out pure white. You may think the color is not being averaged properly, but the strange part is, when a put a printf statement in the code to check the value of the color, it works. When the printf is commented out, the value is Not a Number (NaN), producing the white.... How can a printf statement cause this?


//check for reflections
if (hit.obj->specular.x > 0 || hit.obj->specular.y > 0 ||
hit.obj->specular.z > 0) {
int g,k;
g = scene->glossRays; //this value is 1.
Color newCol = {0,0,0}; // Color is 3 doubles for rgb

for (k = 0; k < g; k++) {
Ray rray; //ray is a vector and direction

if (hit.obj->glossy > 0.0) {
rray = reflectedRayG(ray, &normal, &hitPt, hit.obj->glossy);
} //glossy reflections call

else {
rray = reflectedRay(ray, &normal, &hitPt);
} //non glossy reflections

Color rc = shootRay(scene, &rray, bounce +1);
v3Print(&rc); // this is the printf to stderr that prints the color
// if commented out, newCol is NaN
// if left in, it works properly

newCol.x += hit.obj->specular.x * rc.x;
newCol.y += hit.obj->specular.y * rc.y;
newCol.z += hit.obj->specular.z * rc.z;
}// for k
v3Print(&newCol); //error checking color
newCol = v3Scale(&newCol, 1/(float)g);
c = v3Sum(&c, &newCol);
}//if reflections
Apr 25 '07 #1
2 1206
Banfa
9,065 Expert Mod 8TB
This sort of symptom is often indicative of a dangling pointer and that in turn means the the source of the problem is not necessarily in the piece of code where the error comes to light.

You will have to check you code for possible writes to invalid pointers.
Apr 25 '07 #2
price3
2
You were exactly right. The part of my light structure that contained the location was being stored as a pointer, not a vector, and was dropping off the stack. I would have found it sooner if it had actually crashed when reading NaN values in a vector instead of outputting the color white. Thanks so much!
Apr 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dan | last post by:
php is acting funny after an upgrade from RH7.3 to RH9.0. My hope is that someone can see the output and recognize what the problem might be. I have a set of php scripts set to run from the...
14
by: Jive | last post by:
I've un-installed Python 2.4, re-installed Python 2.3 and PythonWin for 2.3, but it's still broke. When I start PythonWin, sometimes it looks like it is going to be okay. But as soon as I open...
9
by: Josh Mayfield | last post by:
Note: There is considerable background detail here, but I do have three questions, which are clearly marked and appear right before the sample code. I have a legitimate need to launch an EXE...
0
by: info | last post by:
Hi! Latest Windows Update broke my VS2005 Beta. I cannot uninstall, repair, etc. I am ready to buy a licence but in Italy it isn't available yet. I am ready to install a 90day trial but the...
6
by: Rob Sell | last post by:
Greetings all, Yesterday I upgraded from 7.3 to 7.4 now psql doesn't work! I get the following error. psql: relocation error: psql: undefined symbol: get_progname Any ideas out there? Rob
2
by: martin | last post by:
Hi, I have an intranet that runs on a win 2k box. This win 2k box is a domain controller. The intranet has absolutly nothing to do with .dot net all. It is wriiten in classic asp and uses ado...
21
by: Alok | last post by:
While posting a comment on http://www.reddit.com I got an error page with the following curious statement on it. "reddit broke (sorry)" "looks like we shouldn't have stopped using lisp..." ...
0
by: Lars Eighner | last post by:
Has anyone else noticed that Google broke itself within the last day or so? As near as I can tell, it accomplished this by trying to wrap links to additional pages of results and the "next" link...
1
by: mark4asp | last post by:
I moved a page to another web-site and now it's broke! I had 5 pages in their own web-site. These pages have now been moved to another web-site. Everything is fine except that one of the pages,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.