Wierd problem (well the way i see it...) with floats

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Wierd problem (well the way i see it...) with floats

Post by Ghoti »

Hi folks,

here is the problem: I have this struct:

Code: Select all

typedef struct { float			u, v; 
					 int			color;
					 float			x, y, z; } ObjVertexB;

typedef struct { float u, v;	} ObjTexCoord;	// texture coordinates
	
then i have this function: (not important code is left out to save space)

Code: Select all

ObjTexCoord		TexCoords[ iNumberOfTexCoords ];

....some code


for &#40;j=0;j<iNumberOfFaces-1; j++&#41;&#123;
				if &#40;FacesDone&#91;j&#93; == TRUE&#41; &#123;&#125;
				else &#123;
					if &#40;CompareFaces&#40;&ComparedFace, &Faces&#91; j &#93;&#41; == 2&#41; &#123;
						FacesDone&#91;j&#93; = TRUE;
						ComparedFace = Faces&#91; j &#93;;
						tmpObj->Strips&#91;iStripNr&#93;.Vertices&#91;j&#93;.u = TexCoords&#91;0&#93;.u;
						tmpObj->Strips&#91;iStripNr&#93;.Vertices&#91;j&#93;.v = TexCoords&#91;0&#93;.v;
						
						tmpObj->Strips&#91;iStripNr&#93;.Vertices&#91;j&#93;.color = 0xffff0000;
						tmpObj->Strips&#91;iStripNr&#93;.Vertices&#91;j&#93;.x = Vertices&#91;iNewCoord&#93;.x;
						tmpObj->Strips&#91;iStripNr&#93;.Vertices&#91;j&#93;.y = Vertices&#91;iNewCoord&#93;.y;
						tmpObj->Strips&#91;iStripNr&#93;.Vertices&#91;j&#93;.z = Vertices&#91;iNewCoord&#93;.z;
						
						VerticesCount++;
						j = 0;
					&#125;
				&#125;
			&#125;
The first u value of the vertices is filled and no crash occurs, however the .v crashes. If i comment it out so that only the u is filled and the program doesn't crash.

now the TexCoords is filled with this code:

Code: Select all

if &#40;&#40;fp = fopen&#40;filename, "rb"&#41;&#41; == NULL&#41; &#123; iNumberOfGroups = -1; return; &#125;
		while&#40;!feof&#40;fp&#41;&#41;
		&#123;
			fgets&#40;ReadBuffer, 256, fp&#41;;
			if &#40;strncmp&#40;"g default", ReadBuffer, 9&#41; == 0 &#41;
			&#123;
				if &#40;iNumberOfGroups == 0&#41; &#123;

				&#125;
				else &#123;
					iNumberOfGroups++;
				&#125;
			&#125;
			else if &#40;strncmp&#40;"v ", ReadBuffer, 2&#41; == 0 &#41;
			&#123;
				sscanf&#40;&#40;ReadBuffer+2&#41;, "%f%f%f",&Vertices&#91; vc &#93;.x, &Vertices&#91; vc &#93;.y, &Vertices&#91; vc &#93;.z&#41;; 
				vc++;
			&#125;
			else if &#40;strncmp&#40;"vt ", ReadBuffer, 3&#41; == 0 &#41;
			&#123;
				sscanf&#40;&#40;ReadBuffer+3&#41;, "%f%f",&TexCoords&#91; tc &#93;.u, &TexCoords&#91; tc &#93;.v&#41;; 
				tc++;
			&#125;

			else if &#40;strncmp&#40;"f ", ReadBuffer, 2&#41; == 0 &#41;
			&#123;
				
				char *pSplitString = NULL;
				int Waste;
				i=0;
				pSplitString = strtok&#40;&#40;ReadBuffer+2&#41;," \t\n"&#41;;

				do &#123;

					sscanf&#40;&#40;pSplitString&#41;, "%d/%d/%d",&Faces&#91; fc &#93;.vertices&#91; i &#93;, &Faces&#91; fc &#93;.textc&#91; i &#93;,&Waste&#41;; 
					Faces&#91; fc &#93;.textc&#91; i &#93; -= 1;		// 1 down because the obj file objects start at 1 and arrays start at 0
					Faces&#91; fc &#93;.vertices&#91; i &#93; -= 1;
					pSplitString = strtok&#40;NULL," \t\n"&#41;;
					i += 1;
				&#125;
				while&#40; pSplitString &#41;;
				
				
				
				
				fc++;
			&#125;
		&#125;
		fclose&#40;fp&#41;;
why does it crash when i fill the v value and not the u value?

i hope i gave enough info otherwise please ask so i can provide

thanks in advance
User avatar
ReKleSS
Posts: 73
Joined: Sat Jun 18, 2005 12:57 pm
Location: Melbourne, Australia

Post by ReKleSS »

Could you use psplink or something to check what the error is? I'm guessing bus error, but better not to waste time on the wrong problem...

Anyway, how is tmpObj declared?
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

ReKleSS wrote: Anyway, how is tmpObj declared?
Plus, how is it allocated.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Hi,

first of all in psplink i get no error. It doesn't crash and renders the object. (all wrong but thats another thing to fix later on.)

however when i run it on my psp it crashes... why is this?

anyway for your questions:

i declare:

Code: Select all

MeshB Level;
sprintf&#40;sBuffer, "Objects/DesertHouse1.obj"&#41;;
		LoadObject&#40;sBuffer, &Level&#41;;
as you can see i pass it to the function in which the error occurs

Code: Select all

void LoadObject&#40;const char *filename, MeshB *tmpObj&#41;;


meshb struct:

Code: Select all

typedef struct &#123; float			u, v; 
					 int			color;
					 float			x, y, z; &#125; ObjVertexB;	// vertex to render

	typedef struct &#123; unsigned int	iNumberOfVertices;
					 ObjVertexB		*Vertices; &#125; ObjStrip;

	typedef struct _MeshB &#123;	unsigned int	iNumberOfStrips;
							ObjStrip		*Strips; &#125; MeshB;
As for the last question i don't know
Post Reply