Skip to content

Commit b918f68

Browse files
pal2img: handle errors when saving an image file
1 parent 9aaf3bd commit b918f68

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/tools/pal2img.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int main( int argc, char ** argv )
4747
}
4848

4949
const char * paletteFileName = argv[1];
50-
const char * outputImage = argv[2];
50+
const char * outputFileName = argv[2];
5151

5252
{
5353
StreamFile paletteStream;
@@ -65,25 +65,28 @@ int main( int argc, char ** argv )
6565
fheroes2::setGamePalette( palette );
6666
}
6767

68-
fheroes2::Image output( 256, 256 );
69-
output.reset();
68+
fheroes2::Image image( 256, 256 );
69+
image.reset();
7070
// We do not need to care about the transform layer.
71-
output._disableTransformLayer();
71+
image._disableTransformLayer();
7272

7373
// These color indexes are from PAL::GetCyclingPalette() method.
7474
const std::set<uint8_t> cyclingColors{ 214, 215, 216, 217, 218, 219, 220, 221, 231, 232, 233, 234, 235, 238, 239, 240, 241 };
7575

7676
for ( uint8_t y = 0; y < 16; ++y ) {
7777
for ( uint8_t x = 0; x < 16; ++x ) {
78-
fheroes2::Fill( output, x * 16, y * 16, 16, 16, x + y * 16 );
78+
fheroes2::Fill( image, x * 16, y * 16, 16, 16, x + y * 16 );
7979

8080
if ( cyclingColors.count( x + y * 16 ) > 0 ) {
81-
fheroes2::Fill( output, x * 16, y * 16, 4, 4, 0 );
81+
fheroes2::Fill( image, x * 16, y * 16, 4, 4, 0 );
8282
}
8383
}
8484
}
8585

86-
fheroes2::Save( output, outputImage );
86+
if ( !fheroes2::Save( image, outputFileName ) ) {
87+
std::cerr << "Error writing to file " << outputFileName << std::endl;
88+
return EXIT_FAILURE;
89+
}
8790

8891
return EXIT_SUCCESS;
8992
}

0 commit comments

Comments
 (0)