Browse Source

protect better against version changes

David Rose 22 years ago
parent
commit
4650d62c0d

+ 6 - 0
pandatool/src/egg-palettize/eggPalettize.cxx

@@ -645,6 +645,12 @@ run() {
            << " and try again).\n\n";
       exit(1);
     }
+
+    if (!pal->is_valid()) {
+      nout << FilenameUnifier::make_user_filename(state_filename)
+           << " could not be properly read.  You will need to remove it.\n";
+      exit(1);
+    }
   }
 
   if (_report_pi) {

+ 19 - 0
pandatool/src/palettizer/palettizer.cxx

@@ -101,6 +101,8 @@ public:
 ////////////////////////////////////////////////////////////////////
 Palettizer::
 Palettizer() {
+  _is_valid = true;
+
   _generated_image_pattern = "%g_palette_%p_%i";
   _map_dirname = "%g";
   _shadow_dirname = "shadow";
@@ -123,6 +125,18 @@ Palettizer() {
   _remap_char_uv = RU_poly;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Palettizer::is_valid
+//       Access: Public
+//  Description: Returns true if the palette information file was read
+//               correctly, or false if there was some error and the
+//               palettization can't continue.
+////////////////////////////////////////////////////////////////////
+bool Palettizer::
+is_valid() const {
+  return _is_valid;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Palettizer::report_pi
 //       Access: Public
@@ -1041,6 +1055,11 @@ fillin(DatagramIterator &scan, BamReader *manager) {
   TypedWritable::fillin(scan, manager);
 
   _read_pi_version = scan.get_int32();
+  if (_read_pi_version > _pi_version || _read_pi_version < _min_pi_version) {
+    // Oops, we don't know how to read this palette information file.
+    _is_valid = false;
+    return;
+  }
   if (_read_pi_version >= 12) {
     _generated_image_pattern = scan.get_string();
   }

+ 3 - 0
pandatool/src/palettizer/palettizer.h

@@ -48,6 +48,7 @@ class Palettizer : public TypedWritable {
 public:
   Palettizer();
 
+  bool is_valid() const;
   void report_pi() const;
   void report_statistics() const;
 
@@ -88,6 +89,8 @@ public:
 
   static RemapUV string_remap(const string &str);
 
+  bool _is_valid;
+
   // These values are not stored in the bam file, but are specific to
   // each session.
   TxaFile _txa_file;