Skip to content

Commit

Permalink
do not write to log file if cannot open
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Mar 15, 2020
1 parent e34b3e0 commit 42cda6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lua/extra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,11 @@ function log(fmt, ...)
local plat = am.platform
if plat == "windows" or plat == "linux" or plat == "osx" then
local f = io.open(am.app_data_dir.."log.txt", first_log and "w" or "a")
f:write(msg)
f:write("\n")
f:close()
if f then
f:write(msg)
f:write("\n")
f:close()
end
end

if am._main_window then
Expand Down
4 changes: 2 additions & 2 deletions src/am_spritepack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static void write_data() {
double w, h, adv;
FILE *f = am_fopen(lua_filename, "w");
if (f == NULL) {
fprintf(stderr, "unable to open %s for writing\n", lua_filename);
fprintf(stderr, "unable to open %s for writing: %s\n", lua_filename, strerror(errno));
return;
}
fprintf(f, "local font_data = {\n");
Expand Down Expand Up @@ -365,7 +365,7 @@ static void write_png() {
atlas_data, atlas_width, atlas_height, 4, &len);
FILE *f = am_fopen(png_filename, "wb");
if (f == NULL) {
fprintf(stderr, "unable to open %s for writing\n", png_filename);
fprintf(stderr, "unable to open %s for writing: %s\n", png_filename, strerror(errno));
return;
}
fwrite(png_data, len, 1, f);
Expand Down

0 comments on commit 42cda6d

Please sign in to comment.