Skip to content

floem app fails to launch when using libloading #858

@woodworthkyle

Description

@woodworthkyle

107 talks about a stack overflow when trying to use floem with libloading. I've been trying to do something similar with floem, but I don't get a stack overflow error. The application just terminates without ever showing a window or error message.

I'm assuming the way VIEW_STORAGE is defined (with thread_local! and static), it is forced to be stored at the same memory location across floem instances in the same thread. And by instances I mean linked instances of floem. In this case the host app and plugin have linked instances of floem but when running they live on the same thread. So they share the VIEW_STORAGE memory location (I think this is an over-simplified version of how rust actually compiles this down, but it boils down to this core concept). This is verified by printing out the raw pointer location of the VIEW_STORAGE of the host app and the VIEW_STORAGE of the plugin and observing that they were the same. However, something happens with the control machinery of VIEW_STORAGE and how it creates keys. It looks like the plugin starts over with key creation and will essentially start to overwrite the contents of VIEW_STORAGE from the perspective of the host app.

I've verified this by "sending" the text function (the one that creates a static label) to the plugin and utilizing this function to create a text label. When using this sent function, I am able to render a window without the application "crashing". When I use the "normal" text function from the namespace of the plugin, the application fails to launch (presumably for overwriting the first entry in the VIEW_STORAGE struct). So it seems like there are two "instances" of floem that fight over VIEW_STORAGE when libloading is used.

One solution would be to libload floem as its own library so that applications can make use of it via an ABI. This would allow for smaller end-user binaries (I think) and for other languages to hook into the framework (like python+Qt; I would love a floem python interface :) ). I keep reading that rust's ABI is unstable, but I'm not entirely sure the implications of this. Another solution might involve something like a "shared" floem API of sorts. Something that allows "plugins" to talk to a common set of functions more easily.

It took some hours of messy code to get to this point, so I will post a simplified example tomorrow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions