Преглед изворни кода

Merge pull request #34 from AlexVigo/patch-1

Update GLS.FileSTL.pas
glscene пре 1 година
родитељ
комит
f656c01971
1 измењених фајлова са 19 додато и 22 уклоњено
  1. 19 22
      Source/GLS.FileSTL.pas

+ 19 - 22
Source/GLS.FileSTL.pas

@@ -146,27 +146,24 @@ var
     P: Int64;
     Header: TSTLHeader;
     PHeader: ^TSTLHeader;
-  begin
-    Result := True;
-    try
-      if (AStream.Size - AStream.Position) < SizeOf(TSTLHeader) then Abort;
-      P := AStream.Position;
-      PHeader := @Header;
-      AStream.Read(PHeader^, SizeOf(Header));
-      AStream.Position := P;
-      if not
-      (
-        (Header.Dummy[0] = 's') and
-        (Header.Dummy[1] = 'o') and
-        (Header.Dummy[2] = 'l') and
-        (Header.Dummy[3] = 'i') and
-        (Header.Dummy[4] = 'd')
-      ) then Exit;
-      if AStream.Size <> (SizeOf(TSTLHeader) + (Header.Faces * FACET_SIZE)) then Abort;
-      Result := True;
-    except
-      Result := False;
-    end;
+   begin
+    if (AStream.Size - AStream.Position) < SizeOf(TSTLHeader) then
+      raise Exception.Create('STL file is broken!');
+    P := AStream.Position;
+    PHeader := @Header;
+    AStream.Read(PHeader^, SizeOf(Header));
+    AStream.Position := P;
+    Result := not
+    (
+      (Header.Dummy[0] = 's') and
+      (Header.Dummy[1] = 'o') and
+      (Header.Dummy[2] = 'l') and
+      (Header.Dummy[3] = 'i') and
+      (Header.Dummy[4] = 'd')
+    );
+    if Result and
+      (AStream.Size <> (SizeOf(TSTLHeader) + (Header.Faces * FACET_SIZE))) then
+      raise Exception.Create('Binary STL file is broken!');
   end;
 
 begin
@@ -319,4 +316,4 @@ initialization
   STLUseEmbeddedColors := False;
   RegisterVectorFileFormat('stl', 'Stereolithography files', TGLSTLVectorFile);
 
-end.
+end.