simplify formats

This commit is contained in:
vaxerski 2022-07-25 22:40:34 +02:00
parent db899e00e7
commit b0d91cbf3a
3 changed files with 36 additions and 43 deletions

View File

@ -890,6 +890,34 @@ void CCompositor::cleanupFadingOut(const int& monid) {
} }
for (auto& ls : m_vSurfacesFadingOut) { for (auto& ls : m_vSurfacesFadingOut) {
// sometimes somehow fucking happens wtf
bool exists = false;
for (auto& m : m_vMonitors) {
for (auto& lsl : m->m_aLayerSurfaceLists) {
for (auto& lsp : lsl) {
if (lsp.get() == ls) {
exists = true;
break;
}
}
if (exists)
break;
}
if (exists)
break;
}
if (!exists) {
m_vSurfacesFadingOut.erase(std::remove(m_vSurfacesFadingOut.begin(), m_vSurfacesFadingOut.end(), ls));
Debug::log(LOG, "Fading out a non-existent LS??");
return;
}
if (ls->monitorID != monid) if (ls->monitorID != monid)
continue; continue;

View File

@ -58,37 +58,20 @@ void Debug::log(LogLevel level, const char* fmt, ...) {
ofs << "] "; ofs << "] ";
} }
char buf[LOGMESSAGESIZE] = ""; char* outputStr = nullptr;
char* outputStr;
int logLen;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
logLen = vsnprintf(buf, sizeof buf, fmt, args); vasprintf(&outputStr, fmt, args);
va_end(args); va_end(args);
if ((long unsigned int)logLen < sizeof buf) { std::string output = std::string(outputStr);
outputStr = strdup(buf); free(outputStr);
} else {
outputStr = (char*)malloc(logLen + 1);
if (!outputStr) { ofs << output << "\n";
printf("CRITICAL: Cannot alloc size %d for log! (Out of memory?)", logLen + 1);
return;
}
va_start(args, fmt);
vsnprintf(outputStr, logLen + 1U, fmt, args);
va_end(args);
}
ofs << outputStr << "\n";
ofs.close(); ofs.close();
// log it to the stdout too. // log it to the stdout too.
std::cout << outputStr << "\n"; std::cout << output << "\n";
// free the log
free(outputStr);
} }

View File

@ -83,32 +83,14 @@ void wlr_signal_emit_safe(struct wl_signal *signal, void *data) {
} }
std::string getFormat(const char *fmt, ...) { std::string getFormat(const char *fmt, ...) {
char buf[LOGMESSAGESIZE] = ""; char* outputStr = nullptr;
char* outputStr;
int logLen;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
logLen = vsnprintf(buf, sizeof buf, fmt, args); vasprintf(&outputStr, fmt, args);
va_end(args); va_end(args);
if ((long unsigned int)logLen < sizeof buf) {
outputStr = strdup(buf);
} else {
outputStr = (char*)malloc(logLen + 1);
if (!outputStr) {
printf("CRITICAL: Cannot alloc size %d for log! (Out of memory?)", logLen + 1);
return "";
}
va_start(args, fmt);
vsnprintf(outputStr, logLen + 1U, fmt, args);
va_end(args);
}
std::string output = std::string(outputStr); std::string output = std::string(outputStr);
free(outputStr); free(outputStr);
return output; return output;