Hello, I recently implemented new code into my program that made him end into a segfault. Started to print messages on the terminal to be able to locate the precise line. I located such line, it is:
I know it shall be this line because the "TEST2" is not being printed.
However if I add an "exit(-1)" soon after the "TEST2" cout, before anything else, the program stop crashing.
How is that possible? The fact that isn't crashing after the insertion of "exit (-1)" would only make sense if problematic line was another one AFTER the exit (-1) insertion.
Can it be related to multithreading? It is a multithreaded program, but the issue happens even if I send only of the threads to return reaching this point of the code.
No idea of what to do, so any help might prove useful.
ne55, I putted a cout << "final_color: " << final_color.red << ' ' << final_color.green << ' ' << final_color.blue << endl; between cout << "final_color: " << final_color.red << ' ' << final_color.green << ' ' << final_color.blue << endl; and cout << "TEST2" << endl;
with the intention of allowing gdb to print its values.
Now I am receiving the segfault even with a exit (-1) after cout << "TEST2" << endl;
What do you mean by
are those variables `valarray' or something?
If I change "final_color" to final_color = diffuse_color * mat.ks; it seems to run fine (at least no segfault
To change it to final_color = /*diffuse_color * mat.ks +*/ specular_color * mat.kd; also stops it from segfault.
So is this related to something I am doing with operator overloading (everything in the line are "Colors")
I have three operator overloading operations that works with two colors:
You should review functions in your favorite textbook.
Color Color::operator+= (const Color& c)
Returns nothing, despite claiming to return a Color; flowing off the end of a function results in a program whose behavior is undefined.
Color& Color::operator* (const Color& c, const Color &d)
Returns a dangling reference. Attempts to access the result yields a program whose behavior is undefined.
Color& Color::operator+ (const Color& c, const Color &d)
Returns nothing, despite claiming to return a Color. Flowing off the end of a function results in a program whose behavior is undefined.