Bladeren bron

Replace assert with more helpful error

rdb 11 jaren geleden
bovenliggende
commit
d7b21c9aeb
1 gewijzigde bestanden met toevoegingen van 11 en 4 verwijderingen
  1. 11 4
      panda/src/gobj/texture.cxx

+ 11 - 4
panda/src/gobj/texture.cxx

@@ -3314,14 +3314,21 @@ do_read_one(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpa
   if (!alpha_fullpath.empty()) {
   if (!alpha_fullpath.empty()) {
     // Make the original image a 4-component image by taking the
     // Make the original image a 4-component image by taking the
     // grayscale value from the second image.
     // grayscale value from the second image.
+
     image.add_alpha();
     image.add_alpha();
 
 
     if (alpha_file_channel == 4 ||
     if (alpha_file_channel == 4 ||
         (alpha_file_channel == 2 && alpha_image.get_num_channels() == 2)) {
         (alpha_file_channel == 2 && alpha_image.get_num_channels() == 2)) {
-      // Use the alpha channel.
-      for (int x = 0; x < image.get_x_size(); x++) {
-        for (int y = 0; y < image.get_y_size(); y++) {
-          image.set_alpha(x, y, alpha_image.get_alpha(x, y));
+
+      if (!alpha_image.has_alpha()) {
+        gobj_cat.error()
+          << alpha_fullpath.get_basename() << " has no channel " << alpha_file_channel << ".\n";
+      } else {
+        // Use the alpha channel.
+        for (int x = 0; x < image.get_x_size(); x++) {
+          for (int y = 0; y < image.get_y_size(); y++) {
+            image.set_alpha(x, y, alpha_image.get_alpha(x, y));
+          }
         }
         }
       }
       }
       cdata->_alpha_file_channel = alpha_image.get_num_channels();
       cdata->_alpha_file_channel = alpha_image.get_num_channels();