Browse Source

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

customisations
alemart 11 months ago
parent
commit
4e3fe8e564
1 changed files with 7 additions and 3 deletions
  1. 7
    3
      src/trackers/image-tracker/reference-image-database.ts

+ 7
- 3
src/trackers/image-tracker/reference-image-database.ts View File

142
 
142
 
143
         // locked database?
143
         // locked database?
144
         if(this._locked)
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
         // busy loading another image?
147
         // busy loading another image?
148
         if(this._busy)
148
         if(this._busy)
150
 
150
 
151
         // reached full capacity?
151
         // reached full capacity?
152
         if(this.count >= this.capacity)
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
         // check for duplicate names
159
         // check for duplicate names
156
         if(this._database.find(entry => entry.referenceImage.name === referenceImage.name) !== undefined)
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
         // load the media and add the reference image to the database
163
         // load the media and add the reference image to the database
160
         this._busy = true;
164
         this._busy = true;

Loading…
Cancel
Save