-
-
Notifications
You must be signed in to change notification settings - Fork 64
How does it work?
Warning
This is WIP and meant to be read alongside the code it links to.
An attempt at documenting parts of the codebase, outside of code comments, for clarity.
Meson sets -DG_LOG_DOMAIN="Tuba"
for C, allowing us to see debug logs for just Tuba, by setting G_MESSAGES_DEBUG=Tuba
when running Tuba.
Debugging segfaults and critical logs requires some gdb usage. gdb dev.geopjr.Tuba
will launch gdb, but to debug critical logs, you need to set G_DEBUG=fatal-criticals
. You might need some debug symbols but gdb will guide you on how to install them.
To begin, type run
. Tuba will now launch. Then do the required steps until it segfaults or a critical log shows up, at which point gdb will catch it. You can now access the backtrace. I usually do it line by line by typing up
again and again until I stumble upon what caused exactly caused it. It will show you the exact line and file in Vala so you don't need to worry about C much.
Most of Tuba's memory leaks are cause by self ref lambdas. The solution is to just avoid lambdas when possible.
Instead of:
widget.notify["visible"].connect (() => {
message ("Visibility Changed");
});
Do:
widget.notify["visible"].connect (on_visibility_changed);
void on_visibility_changed () {
message ("Visibility Changed");
}
Sometimes that might require a bit more boilerplate by either subclassing widgets to make your own signals or using top level vars/properties. To check if something is leaking easily, add a debug log to the class' destructor:
~Widget () {
debug ("Widget got destroyed");
}
BlurHashes by Wolt are tiny string representations of images to be used as placeholders while the full images are loading. I've extracted it from Tuba into its own library but Tuba doesn't use it yet.
Wolt provides an example C library but it's definitely unoptimized. I combined the best parts of their library with https://github.com/mad-gooze/fast-blurhash/ for Tuba's implementation.
BlurHashes use base83. That being uncommon, means our implementation includes an encoder and a decoder for it. blurhash_to_pixbuf
returns a Gdk::Pixbuf
from a blurhash string.