Kaynağa Gözat

ReferenceImageDatabase.add(): check if the image is valid

customisations
alemart 11 ay önce
ebeveyn
işleme
4e3fe8e564

+ 7
- 3
src/trackers/image-tracker/reference-image-database.ts Dosyayı Görüntüle

@@ -142,7 +142,7 @@ export class ReferenceImageDatabase implements Iterable<ReferenceImage>
142 142
 
143 143
         // locked database?
144 144
         if(this._locked)
145
-            throw new IllegalOperationError(`Can't add reference image to the database: it's locked`);
145
+            throw new IllegalOperationError(`Can't add reference image "${referenceImage.name}" to the database: it's locked`);
146 146
 
147 147
         // busy loading another image?
148 148
         if(this._busy)
@@ -150,11 +150,15 @@ export class ReferenceImageDatabase implements Iterable<ReferenceImage>
150 150
 
151 151
         // reached full capacity?
152 152
         if(this.count >= this.capacity)
153
-            throw new IllegalOperationError(`Can't add reference image to the database: the capacity of ${this.capacity} images has been exceeded.`);
153
+            throw new IllegalOperationError(`Can't add reference image "${referenceImage.name}" to the database: the capacity of ${this.capacity} images has been exceeded.`);
154
+
155
+        // check if the image is valid
156
+        if(!(referenceImage.image instanceof HTMLImageElement) && !(referenceImage.image instanceof HTMLCanvasElement) && !(referenceImage.image instanceof ImageBitmap))
157
+            throw new IllegalArgumentError(`Can't add reference image "${referenceImage.name}" to the database: invalid image`);
154 158
 
155 159
         // check for duplicate names
156 160
         if(this._database.find(entry => entry.referenceImage.name === referenceImage.name) !== undefined)
157
-            throw new IllegalArgumentError(`Can't add reference image to the database: found duplicated name "${referenceImage.name}"`);
161
+            throw new IllegalArgumentError(`Can't add reference image "${referenceImage.name}" to the database: found duplicated name`);
158 162
 
159 163
         // load the media and add the reference image to the database
160 164
         this._busy = true;

Loading…
İptal
Kaydet