forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Wed Sep 13, 2006 4:47 am    Post subject: Wierd problem (well the way i see it...) with floats Reply with quote

Hi folks,

here is the problem: I have this struct:
Code:
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:

ObjTexCoord      TexCoords[ iNumberOfTexCoords ];

....some code


for (j=0;j<iNumberOfFaces-1; j++){
            if (FacesDone[j] == TRUE) {}
            else {
               if (CompareFaces(&ComparedFace, &Faces[ j ]) == 2) {
                  FacesDone[j] = TRUE;
                  ComparedFace = Faces[ j ];
                  tmpObj->Strips[iStripNr].Vertices[j].u = TexCoords[0].u;
                  tmpObj->Strips[iStripNr].Vertices[j].v = TexCoords[0].v;
                  
                  tmpObj->Strips[iStripNr].Vertices[j].color = 0xffff0000;
                  tmpObj->Strips[iStripNr].Vertices[j].x = Vertices[iNewCoord].x;
                  tmpObj->Strips[iStripNr].Vertices[j].y = Vertices[iNewCoord].y;
                  tmpObj->Strips[iStripNr].Vertices[j].z = Vertices[iNewCoord].z;
                  
                  VerticesCount++;
                  j = 0;
               }
            }
         }
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:
if ((fp = fopen(filename, "rb")) == NULL) { iNumberOfGroups = -1; return; }
      while(!feof(fp))
      {
         fgets(ReadBuffer, 256, fp);
         if (strncmp("g default", ReadBuffer, 9) == 0 )
         {
            if (iNumberOfGroups == 0) {

            }
            else {
               iNumberOfGroups++;
            }
         }
         else if (strncmp("v ", ReadBuffer, 2) == 0 )
         {
            sscanf((ReadBuffer+2), "%f%f%f",&Vertices[ vc ].x, &Vertices[ vc ].y, &Vertices[ vc ].z);
            vc++;
         }
         else if (strncmp("vt ", ReadBuffer, 3) == 0 )
         {
            sscanf((ReadBuffer+3), "%f%f",&TexCoords[ tc ].u, &TexCoords[ tc ].v);
            tc++;
         }

         else if (strncmp("f ", ReadBuffer, 2) == 0 )
         {
            
            char *pSplitString = NULL;
            int Waste;
            i=0;
            pSplitString = strtok((ReadBuffer+2)," \t\n");

            do {

               sscanf((pSplitString), "%d/%d/%d",&Faces[ fc ].vertices[ i ], &Faces[ fc ].textc[ i ],&Waste);
               Faces[ fc ].textc[ i ] -= 1;      // 1 down because the obj file objects start at 1 and arrays start at 0
               Faces[ fc ].vertices[ i ] -= 1;
               pSplitString = strtok(NULL," \t\n");
               i += 1;
            }
            while( pSplitString );
            
            
            
            
            fc++;
         }
      }
      fclose(fp);


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
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
ReKleSS



Joined: 18 Jun 2005
Posts: 73
Location: Melbourne, Australia

PostPosted: Wed Sep 13, 2006 8:44 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Sep 13, 2006 10:01 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Wed Sep 13, 2006 8:22 pm    Post subject: Reply with quote

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:
MeshB Level;
sprintf(sBuffer, "Objects/DesertHouse1.obj");
      LoadObject(sBuffer, &Level);
as you can see i pass it to the function in which the error occurs
Code:
void LoadObject(const char *filename, MeshB *tmpObj);




meshb struct:
Code:
typedef struct { float         u, v;
                int         color;
                float         x, y, z; } ObjVertexB;   // vertex to render

   typedef struct { unsigned int   iNumberOfVertices;
                ObjVertexB      *Vertices; } ObjStrip;

   typedef struct _MeshB {   unsigned int   iNumberOfStrips;
                     ObjStrip      *Strips; } MeshB;


As for the last question i don't know
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group