Additional logging + FFMpeg changes; ffmpeg output will be in the log now
This commit is contained in:
		@@ -61,10 +61,12 @@ using namespace glm;
 | 
			
		||||
  #define POPEN  _popen
 | 
			
		||||
  #define PCLOSE _pclose
 | 
			
		||||
  #define PWRITE_MODE "wb"
 | 
			
		||||
  #define PREAD_MODE "r"
 | 
			
		||||
#else
 | 
			
		||||
  #define POPEN  popen
 | 
			
		||||
  #define PCLOSE pclose
 | 
			
		||||
  #define PWRITE_MODE "w"
 | 
			
		||||
  #define PREAD_MODE "r"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define UV_VERTICES(uvMin, uvMax) \
 | 
			
		||||
 
 | 
			
		||||
@@ -30,20 +30,33 @@ ffmpeg_render
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // ffmpeg output will be piped into the log
 | 
			
		||||
    std::string logOutput = " 2>> \"" + log_path_get() + "\"";
 | 
			
		||||
 | 
			
		||||
#if _WIN32
 | 
			
		||||
    command = string_quote(command);
 | 
			
		||||
    command = string_quote(command) + logOutput;
 | 
			
		||||
#else
 | 
			
		||||
    command += logOutput;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    log_command(command);
 | 
			
		||||
 | 
			
		||||
    FILE* fp = POPEN(command.c_str(), PWRITE_MODE);
 | 
			
		||||
 | 
			
		||||
    if (!fp) 
 | 
			
		||||
    {
 | 
			
		||||
        log_info(std::format(FFMPEG_POPEN_ERROR, strerror(errno)));
 | 
			
		||||
        log_error(std::format(FFMPEG_POPEN_ERROR, strerror(errno)));
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    size_t frameBytes = size.x * size.y * TEXTURE_CHANNELS;
 | 
			
		||||
 | 
			
		||||
// supposedly, might help with video corruption issues on windows?
 | 
			
		||||
#if _WIN32
 | 
			
		||||
    _setmode(_fileno(stdout), _O_BINARY);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    for (const auto& frame : frames) 
 | 
			
		||||
    {
 | 
			
		||||
        std::vector<u8> rgba = texture_download(&frame);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@
 | 
			
		||||
#include "texture.h"
 | 
			
		||||
 | 
			
		||||
#define FFMPEG_POPEN_ERROR "popen() (for FFmpeg) failed!\n{}"
 | 
			
		||||
#define FFMPEG_LOG_BUFFER_SIZE 256
 | 
			
		||||
 | 
			
		||||
static constexpr const char* FFMPEG_GIF_FORMAT =
 | 
			
		||||
"\"{0}\" -y "
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								src/log.cpp
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/log.cpp
									
									
									
									
									
								
							@@ -2,7 +2,12 @@
 | 
			
		||||
 | 
			
		||||
inline std::ofstream logFile;
 | 
			
		||||
 | 
			
		||||
static void _log_write(const std::string& string)
 | 
			
		||||
std::string log_path_get(void)
 | 
			
		||||
{
 | 
			
		||||
    return preferences_path_get() + LOG_PATH;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_write(const std::string& string)
 | 
			
		||||
{
 | 
			
		||||
    std::println("{}", string);
 | 
			
		||||
    
 | 
			
		||||
@@ -13,30 +18,36 @@ static void _log_write(const std::string& string)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_init(const std::string& file)
 | 
			
		||||
void log_init(void)
 | 
			
		||||
{
 | 
			
		||||
    logFile.open(file, std::ios::out | std::ios::trunc);
 | 
			
		||||
    if (!logFile) std::println("{}", std::format(LOG_INIT_ERROR, file));
 | 
			
		||||
    std::string logFilepath = log_path_get();
 | 
			
		||||
    logFile.open(logFilepath, std::ios::out | std::ios::trunc);
 | 
			
		||||
    if (!logFile) std::println("{}", std::format(LOG_INIT_ERROR, logFilepath));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_error(const std::string& error)
 | 
			
		||||
{
 | 
			
		||||
    _log_write(LOG_ERROR_FORMAT + error);
 | 
			
		||||
    log_write(LOG_ERROR_FORMAT + error);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_info(const std::string& info)
 | 
			
		||||
{
 | 
			
		||||
    _log_write(LOG_INFO_FORMAT + info);
 | 
			
		||||
    log_write(LOG_INFO_FORMAT + info);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_warning(const std::string& warning)
 | 
			
		||||
{
 | 
			
		||||
    _log_write(LOG_WARNING_FORMAT + warning);
 | 
			
		||||
    log_write(LOG_WARNING_FORMAT + warning);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_imgui(const std::string& imgui)
 | 
			
		||||
{
 | 
			
		||||
    _log_write(LOG_IMGUI_FORMAT + imgui);
 | 
			
		||||
    log_write(LOG_IMGUI_FORMAT + imgui);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_command(const std::string& command)
 | 
			
		||||
{
 | 
			
		||||
    log_write(LOG_COMMAND_FORMAT + command);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void log_free(void)
 | 
			
		||||
 
 | 
			
		||||
@@ -7,11 +7,15 @@
 | 
			
		||||
#define LOG_INFO_FORMAT "[INFO] "
 | 
			
		||||
#define LOG_IMGUI_FORMAT "[IMGUI] "
 | 
			
		||||
#define LOG_INIT_ERROR "[ERROR] Failed to open log file: {}"
 | 
			
		||||
#define LOG_COMMAND_FORMAT "[COMMAND] "
 | 
			
		||||
#define LOG_PATH "log.txt"
 | 
			
		||||
 | 
			
		||||
void log_init(const std::string& file);
 | 
			
		||||
std::string log_path_get(void);
 | 
			
		||||
void log_init(void);
 | 
			
		||||
void log_write(const std::string& file);
 | 
			
		||||
void log_error(const std::string& error);
 | 
			
		||||
void log_info(const std::string& info);
 | 
			
		||||
void log_warning(const std::string& warning);
 | 
			
		||||
void log_imgui(const std::string& imgui);
 | 
			
		||||
void log_command(const std::string& command);
 | 
			
		||||
void log_free(void);
 | 
			
		||||
@@ -14,7 +14,7 @@ main(s32 argc, char* argv[])
 | 
			
		||||
{
 | 
			
		||||
	State state;
 | 
			
		||||
 | 
			
		||||
	log_init(preferences_path_get() + LOG_PATH);
 | 
			
		||||
	log_init();
 | 
			
		||||
 | 
			
		||||
	if (argc > 0 && argv[1])
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user