On Mon, 28 Jun 2004, Jerry Feldman wrote:
On Mon, 28 Jun 2004 05:55:16 -0500 (EST) Filippos Papadopoulos <filip@cs.uoi.gr> wrote:
Hi. I am developing a 3d application in SuSE Linux 9.0 in C++. I ported the application in WinXP using VStudio2003. The fun stuff is that the application executes in Linux but it crashes immediatelly in WinXP. I think i found what is causing the segfault in windows. I have the following classes (which are bad-coded by the way ;) :
I don't see anything off the top of my head, but have you tried debugging it under the VC Debugger except that in the Cone class you are using Malloc() in the constructor: vertices1 = (float *)malloc( sizeof(float) * 2 * (30 + 1) ); vertices2 = (float *)malloc( sizeof(float) * 2 * (30 + 1) ); Upper = (float *)malloc( sizeof(float) * 3 * (30 + 1) ); Lower = (float *)malloc( sizeof(float) * 3 * (30 + 1) );;
You should use the new operator. Here is an example: vertices1 = new float[2 * (30 + 1)];
I don't think this is your problem, but malloc(3) should not be used in C++ unless you have no other choice. Remember that malloc(3) is a C runtime library function (and you should include <cstdlib>). new is an intrinsic C++ operator.
Also, your public class variables are not initialized in the case where the empty argument Cone constructor is called, but that would possibly cause you trouble in Linux as well as Windows. --
Well i found out the solution. In the begining of the main.cpp i do the following in Linux: float x=2.0, y=6.0f, z=1.5; Cone cone1(Vertex3d(10*x, 0, 10*z, 100), 1, Vertex3d(10*x, 0, 10*z+5, 2),0.00); Cone cone2(Vertex3d(9*x, 0, 9*z, 100), 0.7, Vertex3d(9*x, 0, 9*z+3, 2),0.00); ... In VC++ i did: float x=2.0, y=6.0f, z=1.5; Cone cone1(*(new Vertex3d(10*x, 0, 10*z, 100)), 1, *(new Vertex3d(10*x, 0, 10*z+5, 2)),0.00); Cone cone2(*(new Vertex3d(9*x, 0, 9*z, 100)), 0.7, *(new Vertex3d(9*x, 0, 9*z+3, 2)),0.00); ... and it worked... Maybe gcc is a bit "smarter" (?) with the initializations...