Skip to content

Fix error output #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/SubtitleOctopus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#define emscripten_get_now() 0.0
#endif

// HACK: ass_utils.h couldn't be included due to a compilation error
#ifndef MSGL_ERR
#define MSGL_ERR 1
#endif

int log_level = 3;

typedef struct {
Expand Down Expand Up @@ -67,9 +72,12 @@ void buffer_free(buffer_t *buf) {
void msg_callback(int level, const char *fmt, va_list va, void *data) {
if (level > log_level) // 6 for verbose
return;
printf("libass: ");
vprintf(fmt, va);
printf("\n");

FILE* stream = level <= MSGL_ERR ? stderr : stdout;

fprintf(stream, "libass: ");
vfprintf(stream, fmt, va);
fprintf(stream, "\n");
}

const float MIN_UINT8_CAST = 0.9 / 255;
Expand Down Expand Up @@ -112,15 +120,15 @@ class SubtitleOctopus {
void initLibrary(int frame_w, int frame_h) {
ass_library = ass_library_init();
if (!ass_library) {
printf("ass_library_init failed!\n");
fprintf(stderr, "ass_library_init failed!\n");
exit(2);
}

ass_set_message_cb(ass_library, msg_callback, NULL);

ass_renderer = ass_renderer_init(ass_library);
if (!ass_renderer) {
printf("ass_renderer_init failed!\n");
fprintf(stderr, "ass_renderer_init failed!\n");
exit(3);
}

Expand All @@ -135,7 +143,7 @@ class SubtitleOctopus {
removeTrack();
track = ass_read_file(ass_library, subfile, NULL);
if (!track) {
printf("Failed to start a track\n");
fprintf(stderr, "Failed to start a track\n");
exit(4);
}
}
Expand All @@ -144,7 +152,7 @@ class SubtitleOctopus {
removeTrack();
track = ass_read_memory(ass_library, buf, (size_t)bufsize, NULL);
if (!track) {
printf("Failed to start a track\n");
fprintf(stderr, "Failed to start a track\n");
exit(4);
}
}
Expand Down Expand Up @@ -266,7 +274,7 @@ class SubtitleOctopus {
// make float buffer for blending
float* buf = (float*)buffer_resize(&m_blend, sizeof(float) * width * height * 4, 0);
if (buf == NULL) {
printf("libass: error: cannot allocate buffer for blending");
fprintf(stderr, "libass: cannot allocate buffer for blending\n");
return &m_blendResult;
}
memset(buf, 0, sizeof(float) * width * height * 4);
Expand Down