Skip to content

Commit

Permalink
Improved error reporting and handling for modelplist export.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbuck committed Oct 6, 2012
1 parent 2f70d1f commit 2b5fb12
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions COLLADAViewer2/AGLK/AGLKMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
@class GLKTextureInfo;


#define AGLKMeshMaximumNumberOfVertices (65535)

/////////////////////////////////////////////////////////////////
// Type used to store mesh vertex attribues
typedef struct
Expand Down
7 changes: 4 additions & 3 deletions COLLADAViewer2/AGLK/AGLKMesh.m
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ - (id)copyWithTransform:(GLKMatrix4)transforms
GLKMatrix4Transpose(transforms));
}

const NSUInteger count = self.numberOfIndices;
const NSUInteger count =
MIN(self.numberOfIndices, AGLKMeshMaximumNumberOfVertices);

// Transform all the positions and normals while copying
// vertex attributes into result.
Expand Down Expand Up @@ -417,7 +418,7 @@ - (BOOL)canAppendMesh:(AGLKMesh *)aMesh;
{
NSUInteger offsetIndex =
startNumberOfIndices + [aMesh indexAtIndex:i];
if(65536 > offsetIndex)
if(AGLKMeshMaximumNumberOfVertices < offsetIndex)
{
// Exit loop and method prematurely!!!
return NO;
Expand All @@ -444,7 +445,7 @@ - (void)appendMesh:(AGLKMesh *)aMesh;
{
NSUInteger offsetIndex =
startNumberOfIndices + [aMesh indexAtIndex:i];
if(65536 > offsetIndex)
if(AGLKMeshMaximumNumberOfVertices >= offsetIndex)
{
[self appendIndex:offsetIndex];
}
Expand Down
64 changes: 63 additions & 1 deletion COLLADAViewer2/CVDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ - (NSDictionary *)modelplistTextureInfoPlist

/////////////////////////////////////////////////////////////////
//
- (IBAction)exportModelplist:(id)sender;
- (void)unconditionallyExportModelplist
{
NSSavePanel *sPanel = [NSSavePanel savePanel];

Expand Down Expand Up @@ -231,4 +231,66 @@ - (IBAction)exportModelplist:(id)sender;
completionHandler:savePanelHandler];
}


/////////////////////////////////////////////////////////////////
//
- (void)conditionallyExportModelplist:(NSAlert *)alert
returnCode:(NSInteger)returnCode
contextInfo:(void *)contextInfo;
{
if(NSAlertDefaultReturn == returnCode)
{
[self unconditionallyExportModelplist];
}
}


/////////////////////////////////////////////////////////////////
//
- (IBAction)exportModelplist:(id)sender;
{
NSUInteger cumulativeNumberOfVertices = 0;

// Calculate the total number of vertices in all models
for(COLLADARoot *root in self.allRoots)
{
cumulativeNumberOfVertices +=
root.numberOfVertices.unsignedIntegerValue;
}

if(AGLKMeshMaximumNumberOfVertices <
cumulativeNumberOfVertices)
{
NSAlert *exportAlert =
[NSAlert alertWithMessageText:
NSLocalizedString(
@"Some information will be discared during export.",
@"Some information will be discared during export.")
defaultButton:
NSLocalizedString(
@"Export Anyway",
@"Export Anyway")
alternateButton:
NSLocalizedString(
@"Cancel Export",
@"Cancel Export")
otherButton:nil
informativeTextWithFormat:
NSLocalizedString(
@"The modelplist file format is limited to storing a maximum of %lu vertices. The collection of models being exported contains at least %lu vertices.",
@"The modelplist file format is limited to storing a maximum of %lu vertices. The collection of models being exported contains at least %lu vertices."),
AGLKMeshMaximumNumberOfVertices,
cumulativeNumberOfVertices];

[exportAlert beginSheetModalForWindow:self.windowForSheet
modalDelegate:self
didEndSelector:@selector(conditionallyExportModelplist:returnCode:contextInfo:)
contextInfo:nil];
}
else
{
[self unconditionallyExportModelplist];
}
}

@end

0 comments on commit 2b5fb12

Please sign in to comment.