Skip to content

Commit

Permalink
Added error handling when failing to load TSP file, fixed typo in GUI…
Browse files Browse the repository at this point in the history
… draw routine, cleaned up unused code
  • Loading branch information
AdrianoDiDio committed Sep 5, 2024
1 parent 7cb6352 commit f6943f0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 50 deletions.
4 changes: 4 additions & 0 deletions src/JPModelViewer/BSD.c
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,10 @@ BSDRenderObject_t *BSDLoadStaticRenderObject(BSDRenderObjectElement_t RenderObje
if( RenderObject->Id == 0 ) {
assert(RenderObjectElement.TSPOffset > 0);
RenderObject->TSP = TSPLoad(BSDFile, RenderObjectElement.TSPOffset + BSD_HEADER_SIZE);
if( !RenderObject->TSP ) {
DPrintf("BSDParseRenderObjectData:Failed to load TSP data for RenderObject %u\n",RenderObject->Id);
goto Failure;
}
} else {
if( !BSDParseRenderObjectVertexAndColorData(RenderObject,&RenderObjectElement,BSDFile) ) {
DPrintf("BSDParseRenderObjectData:Failed to parse Vertex and Color data for RenderObject %u\n",RenderObject->Id);
Expand Down
2 changes: 1 addition & 1 deletion src/JPModelViewer/GUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void GUIDrawMainWindow(GUI_t *GUI,RenderObjectManager_t *RenderObjectManager,Vid
if(!CurrentRenderObject) {
igText("No RenderObject selected.");
} else {
igText("Id:%u",CurrentRenderObject->Id, CurrentRenderObject->FileName);
igText("Id:%u",CurrentRenderObject->Id);
igText("FileName:%s",BSDGetRenderObjectFileName(CurrentRenderObject));
igText("Scale:%f;%f;%f",CurrentRenderObject->Scale[0],CurrentRenderObject->Scale[1],CurrentRenderObject->Scale[2]);
igSeparator();
Expand Down
49 changes: 0 additions & 49 deletions src/JPModelViewer/TSP.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,55 +1282,6 @@ int TSPReadNodeChunk(TSP_t *TSP,FILE *InFile,int TSPOffset)
return 1;
}

int TSPReadFaceChunk(TSP_t *TSP,FILE *InFile)
{
int Ret;
int i;
int NumFaces;

if( !TSP || !InFile ) {
bool InvalidFile = (InFile == NULL ? true : false);
printf("TSPReadFaceChunk: Invalid %s\n",InvalidFile ? "file" : "tsp struct");
return 0;
}
if( TSP->Header.NumFaces == 0 ) {
DPrintf("TSPReadFaceChunk:0 faces found in file %s.\n",TSP->FName);
return 0;
}
//HACK:For the moment we calculate the number of faces by using the vertex offset
// Ignoring the NumFace param in the TSP header
// Since it doesn't cause any weird issue with the 3D rendering.
NumFaces = (TSP->Header.VertexOffset - TSP->Header.FaceOffset) / sizeof(TSPFace_t);
if( NumFaces != TSP->Header.NumFaces ) {
DPrintf("Fixed face count from %i to %i (size %li)\n",TSP->Header.NumFaces,NumFaces,sizeof(TSPFace_t));
TSP->Header.NumFaces = NumFaces;
}
TSP->Face = malloc(TSP->Header.NumFaces * sizeof(TSPFace_t));
if( !TSP->Face ) {
DPrintf("TSPReadFaceChunk:Failed to allocate memory for face array\n");
return 0;
}
for( i = 0; i < TSP->Header.NumFaces; i++ ) {
DPrintf("Reading Face %i at %li\n",i,ftell(InFile));
Ret = fread(&TSP->Face[i],sizeof(TSPFace_t),1,InFile);
if( Ret != 1 ) {
DPrintf("TSPReadFaceChunk:Early failure when reading face %i\n",i);
return 0;
}
#if 1
// if( i <= 4 ) {
DPrintf(" -- Face %i --\n",i);
DPrintf("V0:%u\n",TSP->Face[i].V0);
DPrintf("V1:%u\n",TSP->Face[i].V1);
DPrintf("V2:%u\n",TSP->Face[i].V2);
DPrintf("CBA:%u\n",TSP->Face[i].CBA);
DPrintf("TSB:%u\n",TSP->Face[i].TSB);
// }
#endif
}
return 1;
}

int TSPReadVertexChunk(TSP_t *TSP,FILE *InFile)
{
int Ret;
Expand Down

0 comments on commit f6943f0

Please sign in to comment.