Skip to content

Conversation

@vaxerski
Copy link
Member

@vaxerski vaxerski commented Nov 25, 2025

Adds a dynamic cast equivalent for our shared pointers. Tests pass, I hope nothing implodes xD

cc @PaideiaDilemma @gulafaran can yall check I didnt mess something up

@gulafaran
Copy link
Contributor

it imploded.

#0  Hyprutils::Memory::Impl_::impl_base::dataNonNull (this=0x556879867800) at /usr/include/hyprutils/memory/ImplBase.hpp:101
101	                    return m_control->_data && m_object != nullptr;
[Current thread is 1 (Thread 0x7f4c740f0240 (LWP 8228))]
(gdb) bt
#0  Hyprutils::Memory::Impl_::impl_base::dataNonNull (this=0x556879867800) at /usr/include/hyprutils/memory/ImplBase.hpp:101
#1  0x00005568413b256f in Hyprutils::Memory::CSharedPointer<Aquamarine::CBackend>::operator bool (this=0x5568797af218)
    at /usr/include/hyprutils/memory/SharedPtr.hpp:109
#2  0x000055684137e69e in CCompositor::initServer (this=0x5568797af1f0, socketName="", socketFd=-1)
    at /home/tom/dev/Hyprland/src/Compositor.cpp:342
#3  0x00005568416241d9 in main (argc=1, argv=0x7ffcc84100c8) at /home/tom/dev/Hyprland/src/main.cpp:192
/usr/include/hyprutils/memory/ImplBase.hpp:101:39: runtime error: member access within misaligned address 0x000300000002 for type 'struct SControl', which requires 8 byte alignment
0x000300000002: note: pointer points here
<memory cannot be printed>
    #0 0x55e21b7be48a in Hyprutils::Memory::Impl_::impl_base::dataNonNull() /usr/include/hyprutils/memory/ImplBase.hpp:101
    #1 0x55e21b7e503a in Hyprutils::Memory::CSharedPointer<Aquamarine::CBackend>::operator bool() const /usr/include/hyprutils/memory/SharedPtr.hpp:109
    #2 0x55e21b74e777 in CCompositor::initServer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int) /home/tom/dev/Hyprland/src/Compositor.cpp:342
    #3 0x55e21bfab3f3 in main /home/tom/dev/Hyprland/src/main.cpp:192
    #4 0x7f7adf42b045  (/usr/lib64/libc.so.6+0x2b045)
    #5 0x7f7adf42b0f5 in __libc_start_main (/usr/lib64/libc.so.6+0x2b0f5)
    #6 0x55e21b748820 in _start (/home/tom/dev/Hyprland/build/Desktop-Debug/Hyprland+0x48be820)
    ```

@vaxerski
Copy link
Member Author

try now

@gulafaran
Copy link
Contributor

try now

nope

[ERR] [AQ] Failed to open a session
[ERR] [AQ] DRM Backend failed
/usr/include/hyprutils/memory/ImplBase.hpp:103:39: runtime error: member access within misaligned address 0x000300000002 for type 'struct SControl', which requires 8 byte alignment
0x000300000002: note: pointer points here
<memory cannot be printed>
    #0 0x55b4558f4486 in Hyprutils::Memory::Impl_::impl_base::dataNonNull() /usr/include/hyprutils/memory/ImplBase.hpp:103
    #1 0x55b45591b036 in Hyprutils::Memory::CSharedPointer<Aquamarine::CBackend>::operator bool() const /usr/include/hyprutils/memory/SharedPtr.hpp:109
    #2 0x55b455884777 in CCompositor::initServer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int) /home/tom/dev/Hyprland/src/Compositor.cpp:342
    #3 0x55b4560e13ef in main /home/tom/dev/Hyprland/src/main.cpp:192
    #4 0x7fd337a2b045  (/usr/lib64/libc.so.6+0x2b045)
    #5 0x7fd337a2b0f5 in __libc_start_main (/usr/lib64/libc.so.6+0x2b0f5)
    #6 0x55b45587e820 in _start (/home/tom/dev/Hyprland/build/Desktop-Debug/Hyprland+0x48be820)

Segmentation fault         (core dumped) ./Hyprland
Program terminated with signal SIGSEGV, Segmentation fault.
b#0  0x000055b4558f44a9 in Hyprutils::Memory::Impl_::impl_base::dataNonNull (this=0x55b477979990)
    at /usr/include/hyprutils/memory/ImplBase.hpp:103
103	                    return m_control->_data && m_object != nullptr;
[Current thread is 1 (Thread 0x7fd331eec240 (LWP 15070))]
(gdb) bt
#0  0x000055b4558f44a9 in Hyprutils::Memory::Impl_::impl_base::dataNonNull (this=0x55b477979990)
    at /usr/include/hyprutils/memory/ImplBase.hpp:103
#1  0x000055b45591b037 in Hyprutils::Memory::CSharedPointer<Aquamarine::CBackend>::operator bool (this=0x55b4778c1218)
    at /usr/include/hyprutils/memory/SharedPtr.hpp:109
#2  0x000055b455884778 in CCompositor::initServer (this=0x55b4778c11f0, socketName="", socketFd=-1)
    at /home/tom/dev/Hyprland/src/Compositor.cpp:342
#3  0x000055b4560e13f0 in main (argc=1, argv=0x7ffea8956708) at /home/tom/dev/Hyprland/src/main.cpp:192
```

@vaxerski
Copy link
Member Author

you didnt rebuild aq xd

@gulafaran
Copy link
Contributor

you didnt rebuild aq xd

yeah ABI matters it seems ;) disregard the above self inflicted implosions. nested runs, il proceed with a complete rebuild and check live too.

@vaxerski
Copy link
Member Author

yeah and this leaks gotta fix

@PaideiaDilemma
Copy link
Contributor

I am a bit confused.
Dynamic casts don't change a pointer value. they just make the pointer be interpreted as T instead of U right??
If that is the case, we don't need to construct a different impl when we do a dynamic cast. We just need to have SharedPointer be of type T instead of U.
Since we have DeleterFN now, it will even call the correct deleter, because that remains to be the deleter of U and not T.
Am I missing something?

@PaideiaDilemma
Copy link
Contributor

Ok as a cpp noop i didnt know that multiple inheritance can actually change the pointer. I now understand

@vaxerski
Copy link
Member Author

cpp moment

@vaxerski vaxerski force-pushed the memory-dynamic-cast branch from e039b75 to 117d6fc Compare November 27, 2025 12:41
@vaxerski
Copy link
Member Author

Alternative approach. Seems to work. Please test :)

@PaideiaDilemma
Copy link
Contributor

It does seem to work fine.

But idk if it is a good idea to have this pointer in SP.
Idea: maybe somthing like a CDynamicCastWrapper that can wrap (A)SP and (A)WP and does the dynamic cast when you access the pointer?

If we want this: #93, it would be nice if that would also work for WP's.
That way we could have a UP somewhere owning the reference and do dynamic casts on the WP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants