diff --git a/src/Compositor.cpp b/src/Compositor.cpp index c68b5322..ab802a1a 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -890,6 +890,34 @@ void CCompositor::cleanupFadingOut(const int& monid) { } 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) continue; diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp index 59d2d239..367cf8ca 100644 --- a/src/debug/Log.cpp +++ b/src/debug/Log.cpp @@ -58,37 +58,20 @@ void Debug::log(LogLevel level, const char* fmt, ...) { ofs << "] "; } - char buf[LOGMESSAGESIZE] = ""; - char* outputStr; - int logLen; + char* outputStr = nullptr; va_list args; va_start(args, fmt); - logLen = vsnprintf(buf, sizeof buf, fmt, args); + vasprintf(&outputStr, fmt, args); va_end(args); - if ((long unsigned int)logLen < sizeof buf) { - outputStr = strdup(buf); - } else { - outputStr = (char*)malloc(logLen + 1); + std::string output = std::string(outputStr); + free(outputStr); - 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); - } - - ofs << outputStr << "\n"; + ofs << output << "\n"; ofs.close(); // log it to the stdout too. - std::cout << outputStr << "\n"; - - // free the log - free(outputStr); + std::cout << output << "\n"; } diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 3fc6d20e..b7285637 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -83,32 +83,14 @@ void wlr_signal_emit_safe(struct wl_signal *signal, void *data) { } std::string getFormat(const char *fmt, ...) { - char buf[LOGMESSAGESIZE] = ""; - char* outputStr; - int logLen; + char* outputStr = nullptr; va_list args; va_start(args, fmt); - logLen = vsnprintf(buf, sizeof buf, fmt, args); + vasprintf(&outputStr, fmt, 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); - free(outputStr); return output;