core: Label exception handling + Frambuffer checks + headers (#413)

* Added exception handling in label constructor

* Framebuffer fix + moved headers

* added optional header
This commit is contained in:
Jasson 2024-07-09 05:32:49 -04:00 committed by GitHub
parent 3bedae4436
commit d8ccc6f96a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 66 additions and 58 deletions

View file

@ -1,5 +1,6 @@
#include "ConfigManager.hpp"
#include "../helpers/MiscFunctions.hpp"
#include "src/helpers/Log.hpp"
#include <filesystem>
#include <glob.h>
#include <cstring>

View file

@ -1,9 +1,7 @@
#pragma once
#include "../helpers/Log.hpp"
#include <hyprlang.hpp>
#include <optional>
#include <vector>
#include <memory>
#include <unordered_map>

View file

@ -4,7 +4,7 @@
#include "../renderer/Renderer.hpp"
#include "Auth.hpp"
#include "Egl.hpp"
#include "linux-dmabuf-unstable-v1-protocol.h"
#include <sys/wait.h>
#include <sys/poll.h>
#include <sys/mman.h>
@ -1111,7 +1111,7 @@ void CHyprlock::attemptRestoreOnDeath() {
return;
// dirty hack
uint64_t timeNowMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t({0})).count();
uint64_t timeNowMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(0)).count();
const auto LASTRESTARTPATH = std::string{XDG_RUNTIME_DIR} + "/.hyprlockrestart";

View file

@ -3,14 +3,11 @@
#include <wayland-client.h>
#include "ext-session-lock-v1-protocol.h"
#include "fractional-scale-v1-protocol.h"
#include "linux-dmabuf-unstable-v1-protocol.h"
#include "wlr-screencopy-unstable-v1-protocol.h"
#include "viewporter-protocol.h"
#include "Output.hpp"
#include "CursorShape.hpp"
#include "Timer.hpp"
#include "Auth.hpp"
#include <memory>
#include <vector>
#include <condition_variable>

View file

@ -1,5 +1,5 @@
#include "Box.hpp"
#include <cmath>
#include <limits>
#include <algorithm>

View file

@ -1,5 +1,4 @@
#pragma once
#include "Vector2D.hpp"
class CBox {

View file

@ -1,6 +1,5 @@
#include "Jpeg.hpp"
#include "Log.hpp"
#include <jpeglib.h>
#include <sys/stat.h>
#include <sys/types.h>

View file

@ -19,7 +19,7 @@ enum eLogLevel {
std::format(reason, ##__VA_ARGS__), __LINE__, \
([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })().c_str()); \
printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \
*((int*)nullptr) = 1; /* so that we crash and get a coredump */ \
std::abort(); \
}
#define ASSERT(expr) RASSERT(expr, "?")

View file

@ -1,6 +1,6 @@
#pragma once
#include <string>
#include <optional>
std::string absolutePath(const std::string&, const std::string&);

View file

@ -1,6 +1,5 @@
#pragma once
#include <cmath>
#include <format>
#include <hyprlang.hpp>

View file

@ -1,7 +1,9 @@
#include "config/ConfigManager.hpp"
#include "core/hyprlock.hpp"
#include "src/helpers/Log.hpp"
#include <cstddef>
#include <iostream>
void help() {
std::cout << "Usage: hyprlock [options]\n\n"

View file

@ -10,6 +10,8 @@
#include "../helpers/MiscFunctions.hpp"
#include "../helpers/Jpeg.hpp"
#include "../helpers/Webp.hpp"
#include "src/helpers/Color.hpp"
#include "src/helpers/Log.hpp"
CAsyncResourceGatherer::CAsyncResourceGatherer() {
if (g_pHyprlock->getScreencopy())
@ -345,7 +347,7 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
target.cairo = CAIRO;
target.cairosurface = CAIROSURFACE;
target.data = cairo_image_surface_get_data(CAIROSURFACE);
target.size = {layoutWidth / PANGO_SCALE, layoutHeight / PANGO_SCALE};
target.size = {layoutWidth / (double)PANGO_SCALE, layoutHeight / (double)PANGO_SCALE};
std::lock_guard lg{preloadTargetsMutex};
preloadTargets.push_back(target);

View file

@ -1,10 +1,6 @@
#pragma once
#include "Shader.hpp"
#include "../helpers/Box.hpp"
#include "../helpers/Color.hpp"
#include "DMAFrame.hpp"
#include "Texture.hpp"
#include <thread>
#include <atomic>
#include <vector>

View file

@ -1,9 +1,9 @@
#include "DMAFrame.hpp"
#include "linux-dmabuf-unstable-v1-protocol.h"
#include "wlr-screencopy-unstable-v1-protocol.h"
#include "../helpers/Log.hpp"
#include "../core/hyprlock.hpp"
#include "../core/Egl.hpp"
#include <EGL/eglext.h>
#include <libdrm/drm_fourcc.h>
#include <GLES3/gl32.h>

View file

@ -2,7 +2,6 @@
#include "../core/Output.hpp"
#include <gbm.h>
#include "Texture.hpp"
#include "Shared.hpp"
struct zwlr_screencopy_frame_v1;

View file

@ -41,14 +41,14 @@ bool CFramebuffer::alloc(int w, int h, bool highres) {
if (firstAlloc || m_vSize != Vector2D(w, h)) {
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
glTexImage2D(GL_TEXTURE_2D, 0, glFormat, w, h, 0, GL_RGBA, glType, 0);
glTexImage2D(GL_TEXTURE_2D, 0, glFormat, w, h, 0, GL_RGBA, glType, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0);
if (m_pStencilTex) {
glBindTexture(GL_TEXTURE_2D, m_pStencilTex->m_iTexID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
@ -73,15 +73,20 @@ bool CFramebuffer::alloc(int w, int h, bool highres) {
}
void CFramebuffer::addStencil() {
if (!m_pStencilTex) {
Debug::log(ERR, "No stencil texture allocated.");
return;
}
glBindTexture(GL_TEXTURE_2D, m_pStencilTex->m_iTexID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_vSize.x, m_vSize.y, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_vSize.x, m_vSize.y, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_pStencilTex->m_iTexID, 0);
auto status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Failed adding a stencil to fbo!", status);
RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Failed adding a stencil to fbo! (FB status: {})", status);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -99,9 +104,13 @@ void CFramebuffer::release() {
if (m_cTex.m_iTexID)
glDeleteTextures(1, &m_cTex.m_iTexID);
if (m_pStencilTex && m_pStencilTex->m_iTexID)
glDeleteTextures(1, &m_pStencilTex->m_iTexID);
m_cTex.m_iTexID = 0;
m_iFb = -1;
m_vSize = Vector2D();
m_pStencilTex = nullptr;
}
CFramebuffer::~CFramebuffer() {

View file

@ -6,14 +6,11 @@
#include "../core/hyprlock.hpp"
#include "../renderer/DMAFrame.hpp"
#include "mtx.hpp"
#include <GLES3/gl32.h>
#include <GLES3/gl3ext.h>
#include <algorithm>
#include "Shaders.hpp"
#include "src/helpers/Log.hpp"
#include "widgets/PasswordInputField.hpp"
#include "widgets/Background.hpp"
#include "widgets/Label.hpp"

View file

@ -3,7 +3,6 @@
#include <memory>
#include <chrono>
#include <optional>
#include "../core/LockSurface.hpp"
#include "Shader.hpp"
#include "../helpers/Box.hpp"

View file

@ -1,6 +1,7 @@
#include "IWidget.hpp"
#include "../../helpers/Log.hpp"
#include "../../core/hyprlock.hpp"
#include "src/core/Auth.hpp"
#include <chrono>
#include <unistd.h>
#include <pwd.h>

View file

@ -1,6 +1,7 @@
#include "Label.hpp"
#include "../../helpers/Color.hpp"
#include <hyprlang.hpp>
#include <stdexcept>
#include "../Renderer.hpp"
#include "../../helpers/Log.hpp"
#include "../../core/hyprlock.hpp"
@ -13,6 +14,8 @@ CLabel::~CLabel() {
}
static void onTimer(std::shared_ptr<CTimer> self, void* data) {
if (data == nullptr)
return;
const auto PLABEL = (CLabel*)data;
// update label
@ -64,6 +67,7 @@ void CLabel::plantTimer() {
CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) :
outputStringPort(output), shadow(this, props, viewport_) {
try {
labelPreFormat = std::any_cast<Hyprlang::STRING>(props.at("text"));
std::string textAlign = std::any_cast<Hyprlang::STRING>(props.at("text_align"));
std::string fontFamily = std::any_cast<Hyprlang::STRING>(props.at("font_family"));
@ -99,6 +103,13 @@ CLabel::CLabel(const Vector2D& viewport_, const std::unordered_map<std::string,
angle = angle * M_PI / 180.0;
plantTimer();
} catch (const std::bad_any_cast& e) {
Debug::log(ERR, "Failed to construct CLabel: {}", e.what());
throw;
} catch (const std::out_of_range& e) {
Debug::log(ERR, "Missing propperty for CLabel:{}", e.what());
throw;
}
}
bool CLabel::draw(const SRenderData& data) {

View file

@ -42,7 +42,7 @@ class CLabel : public IWidget {
CAsyncResourceGatherer::SPreloadRequest request;
std::shared_ptr<CTimer> labelTimer;
std::shared_ptr<CTimer> labelTimer = nullptr;
CShadowable shadow;
};

View file

@ -1,7 +1,6 @@
#pragma once
#include "../Framebuffer.hpp"
#include "../Texture.hpp"
#include "../../helpers/Color.hpp"
#include "IWidget.hpp"