[Solved] Segment violation when accessing the clipboard

I’m the maintainer of this C++ project:

and I’m trying to add Haiku clipboard support. However, I can’t seem to interface with be_clipboard because calling be_clipboard->Lock() or be_clipboard->Data() causes a segment violation somewhere in the internal library. According to the debugger, this really is happening in the system library itself. However, the built-in clipboard program has almost the same code yet doesn’t have this same error. Something that might be a factor is that the Clipboard project needs GCC 11 or newer to compile, so maybe the compiler is too new?

What can I do to fix this?

You need a BApplication in order to use be_clipboard, otherwise you need to construct the BClipboard object yourself. There are some notes about this in the BeBook

1 Like

Creating a new BClipboard object for the system clipboard worked, thank you! Here’s the commit where it was fixed: Fix Haiku support, fix Show action not syncing with GUI · Slackadays/Clipboard@457657e · GitHub

2 Likes

Welcome Bachatero!
Doesn’t your app clash with the identically named command “clipboard” coming with the system?

It does, but there’s two potential fixes:

  1. Use the baked-in alias “cb” to refer to Clipboard instead, and/or rename the main binary to something like “clipboardjh” (as the full name for branding is Clipboard by Jackson Huff)

  2. Replace the built-in clipboard command (Would this actually be possible? It could actually be if Haiku is still in a Beta state)

How many scripts/utilities rely on the integrated clipboard command? If there aren’t many, then it may actually be a reasonable proposition to do option 2, or 1 if that isn’t possible.

I suppose Jackson Huff’s tool will have to be renamed then, if anyone plans to package it for Haiku. I doubt we’ll rename the system command that was shipped since BeOS days (IIRC).
Personally, I use Haiku’s “clipboard” command in several scripts and functions.

2 Likes