 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Sep 20, 2006 9:42 pm Post subject: Hi i get a bus error |
|
|
Hi i try to do something as simple as this:
| Code: | | tmpObj->ObjMeshPart[iNumberOfGroups].iFaces = fc-Correction; | fc = an int, Correction also. | Code: | typedef struct { unsigned int iFaces;
ObjVertexB *Vertices;
Image* texture; } ObjMeshPart; |
starting, they are 0 and the fc is the total of facecount and the correction is the value for the current face number.
At this line i get an bus error. what exactly is a bus error and what am i doing wrong here? I have read on this forum that bus error mostly indicates that there is an alignment error however codes like:
| Code: | | tmpObj->iNumberOfParts = iNumberOfGroups; | works perfectly and it seems the some kind of code. _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Wed Sep 20, 2006 10:30 pm Post subject: |
|
|
A bus-error could also be that you access a part of the memory that you shouldn't, you might end up with a null-address (or some other that isn't valid memory) when you dereference the pointers in the code you pasted for example. _________________ GE Dominator |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Wed Sep 20, 2006 10:57 pm Post subject: |
|
|
Sorry for beeing suchs a noob but,
what is the difference between the wrong code and the correct code i gave? And what can i do to fix this?
PS i have looked at dereferencing but i don't see what i am doing wrong exactly _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
memon
Joined: 03 Oct 2005 Posts: 63
|
Posted: Thu Sep 21, 2006 10:08 pm Post subject: |
|
|
My best guess is that you use iNumberOfGroups the wrong way. Say you have iNumberOfGroups = 1, and allocate 1 object, then tmpObj->ObjMeshPart[iNumberOfGroups] will access out of bounds. Off by one...
If you want to access the last object and iNumberOfGroups is the number of objects, then it is tmpObj->ObjMeshPart[iNumberOfGroups-1], or I would use: ObjMeshPart* part = &tmpObj->ObjMeshPart[iNumberOfGroups-1]; part-> ... |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Thu Sep 21, 2006 11:33 pm Post subject: |
|
|
No that is not the case at all (well i guess if the following holds:)
this is a piece of my code:
| Code: | if ((fp = fopen(filename, "rb")) == NULL) { iNumberOfGroups = -1; return; }
while(!feof(fp))
{
fgets(ReadBuffer, 256, fp);
if (strncmp("EndGroup", ReadBuffer, 8) == 0 )
{
tmpObj->ObjMeshParts[iNumberOfGroups].Vertices = (ObjVertexB*)malloc((fc-Correction) * 3 * sizeof(ObjVertexB));
//tmpObj->ObjMeshPart[iNumberOfGroups].iNumberOfFaces = fc - Correction;
tmpObj->ObjMeshParts[iNumberOfGroups].iFaces = (fc-Correction);
l = 0;
for (j=Correction;j<fc;j++)
{
for (k=0; k<3; k++)
{
tmpObj->ObjMeshParts[iNumberOfGroups].Vertices[l].u = TexCoords[Faces[j].textc[k]].u;
tmpObj->ObjMeshParts[iNumberOfGroups].Vertices[l].v = -(TexCoords[Faces[j].textc[k]].v);
tmpObj->ObjMeshParts[iNumberOfGroups].Vertices[l].color = 0xffffff00;
tmpObj->ObjMeshParts[iNumberOfGroups].Vertices[l].x = Vertices[Faces[j].vertices[k]].x;
tmpObj->ObjMeshParts[iNumberOfGroups].Vertices[l].y = Vertices[Faces[j].vertices[k]].y;
tmpObj->ObjMeshParts[iNumberOfGroups].Vertices[l].z = Vertices[Faces[j].vertices[k]].z;
l++;
}
}
// the texture for this part.
//sprintf(sBuffer, "Textures/UVtexturesHousePlatDak1024type3.png");
tmpObj->ObjMeshParts[iNumberOfGroups].texture = loadImage(Textures[iNumberOfGroups]);
// increment the group number.
Correction = fc;
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); |
the only part that crashes is the part i mentioned. All the other part where i use the number of group do not crash. as you can see i reuse that variable (i know it is not good code, but i clean up afterwards, thats my way of coding) so it looks like that for some reason the problem lies in the part after the "="
i hope you can lead more out of my code now
greets ghoti _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Fri Sep 22, 2006 11:10 pm Post subject: |
|
|
Hi,
I have solved the problem,
the problem was indeed the index of the array but it origin of the problem lay in the reading of the object file.
every last line of the file was empty therefor the program save the previous line as the last line. This was EndGroup and therefor adding 1 to many with the index.
thanks for the replies. _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
|
|
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
|