@@ -875,14 +875,17 @@ private void TrainingData_EnsureDefaults(TaggedImage image, Image imageData)
875
875
{
876
876
Image currentImageData = gallery . CurrentImageData ( ) ;
877
877
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 ;
880
882
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 ) ;
884
886
885
- image . selections = new int [ ] { x , y , square_size , square_size } ;
887
+ image . selections = new int [ ] { x , y , square_size , square_size } ;
888
+ }
886
889
}
887
890
}
888
891
@@ -1070,6 +1073,8 @@ private void DragTrainingBounds(int deltaX, int deltaY, bool diagonalsMaintainAs
1070
1073
{
1071
1074
// account for how the image is currently scaled to the screen
1072
1075
Image image = gallery . CurrentImageData ( ) ;
1076
+ if ( image == null ) return ;
1077
+
1073
1078
int imgW = image . Size . Width ;
1074
1079
int imgH = image . Size . Height ;
1075
1080
deltaX = ( int ) ( deltaX / ( imageBounds . Width / imgW ) ) ;
@@ -1318,15 +1323,19 @@ public Image CurrentImageData()
1318
1323
return null ;
1319
1324
1320
1325
TaggedImage currentImage = this . CurrentImage ( ) ;
1321
- Image currentImageData ;
1326
+ Image currentImageData = null ;
1322
1327
1323
1328
if ( imageData . ContainsKey ( currentImage ) )
1324
1329
{
1325
1330
currentImageData = imageData [ currentImage ] ;
1326
1331
}
1327
1332
else
1328
1333
{
1329
- currentImageData = Image . FromFile ( currentImage . filepath ) ;
1334
+ try
1335
+ {
1336
+ currentImageData = Image . FromFile ( currentImage . filepath ) ;
1337
+ }
1338
+ catch ( Exception ex ) { }
1330
1339
1331
1340
// naive pruning solution since dictionaries aren't ordered, just wipe the dictionary. Could check for neighbours from this.images list
1332
1341
if ( this . imageData . Count > max_images_in_memory ) {
0 commit comments