@@ -875,14 +875,17 @@ private void TrainingData_EnsureDefaults(TaggedImage image, Image imageData)
875875 {
876876 Image currentImageData = gallery . CurrentImageData ( ) ;
877877
878- int imgW = currentImageData . Width ;
879- int imgH = currentImageData . Height ;
878+ if ( currentImageData != null )
879+ {
880+ int imgW = currentImageData . Width ;
881+ int imgH = currentImageData . Height ;
880882
881- int square_size = Math . Min ( imgW , imgH ) ;
882- int x = ( square_size == imgW ) ? 0 : Math . Max ( 0 , imgW / 2 - square_size / 2 ) ;
883- int y = ( square_size == imgH ) ? 0 : Math . Max ( 0 , imgH / 2 - square_size / 2 ) ;
883+ int square_size = Math . Min ( imgW , imgH ) ;
884+ int x = ( square_size == imgW ) ? 0 : Math . Max ( 0 , imgW / 2 - square_size / 2 ) ;
885+ int y = ( square_size == imgH ) ? 0 : Math . Max ( 0 , imgH / 2 - square_size / 2 ) ;
884886
885- image . selections = new int [ ] { x , y , square_size , square_size } ;
887+ image . selections = new int [ ] { x , y , square_size , square_size } ;
888+ }
886889 }
887890 }
888891
@@ -1070,6 +1073,8 @@ private void DragTrainingBounds(int deltaX, int deltaY, bool diagonalsMaintainAs
10701073 {
10711074 // account for how the image is currently scaled to the screen
10721075 Image image = gallery . CurrentImageData ( ) ;
1076+ if ( image == null ) return ;
1077+
10731078 int imgW = image . Size . Width ;
10741079 int imgH = image . Size . Height ;
10751080 deltaX = ( int ) ( deltaX / ( imageBounds . Width / imgW ) ) ;
@@ -1318,15 +1323,19 @@ public Image CurrentImageData()
13181323 return null ;
13191324
13201325 TaggedImage currentImage = this . CurrentImage ( ) ;
1321- Image currentImageData ;
1326+ Image currentImageData = null ;
13221327
13231328 if ( imageData . ContainsKey ( currentImage ) )
13241329 {
13251330 currentImageData = imageData [ currentImage ] ;
13261331 }
13271332 else
13281333 {
1329- currentImageData = Image . FromFile ( currentImage . filepath ) ;
1334+ try
1335+ {
1336+ currentImageData = Image . FromFile ( currentImage . filepath ) ;
1337+ }
1338+ catch ( Exception ex ) { }
13301339
13311340 // naive pruning solution since dictionaries aren't ordered, just wipe the dictionary. Could check for neighbours from this.images list
13321341 if ( this . imageData . Count > max_images_in_memory ) {
0 commit comments