Application becomes unresponsive after launching another libsdl process.

I’m trying to run an sdl application from inside another sdl application, and I’m confused as to why the original application becomes unresponsive.

Repro:

git clone https://github.com/apaz-cli/GraphViewer
cd GraphViewer
git checkout 26a0637e04b44a859ec611cfbbd453127df239db
# Install libsdl2, libsdl2_gfx, libsdl2_ttf, libsdl2_mixer
./build.sh # Creates graph_viewer and filepicker binaries
./graph_viewer.json object_graph.json
# Click on "Open" in the top left.
# Graph viewer then becomes unresponsive until the file picker is closed.

How can I create a file picker in another window that’s responsive? Should I do it from the same process? How should I think about event handling across sdl processes, and across multiple windows?

If you don’t want to block the main thread, you have to use another API for processes or multithreading.
Plain popen(3) is really not a good choice here if you want to keep the main window working as the approach you used is blocking - you wait for the read and process to change its state and during this time you will not do anything else. Replace your popen pipeline with sleeping - it will behave the same.

One way to “fix” this is to put the filepicker handling into an event loop, and check its state on every update call. You can use O_NONBLOCK to not block while reading. Though real world application will involve event loop, I guess for demo like yours you should not bother.

If SDL3 is an option, it has a file picker/chooser API built in.
SDL_ShowOpenFileDialog
SDL_ShowOpenFolderDialog
SDL_ShowSaveFileDialog

Which OS? zenity has been working ok for me on linux. Although you’ll have to use non blocking IO like the person above said

Thanks for the replies. The issue is pretty clearly that I’m blocking on the other process. Whups. Should have thought of that.

I did see that SDL3 solves the issue by introducing its own file picker. I didn’t have to write my own. For unrelated reasons though, I don’t know if I can use SDL3 or not. I thought it would be a bunch of work to get it working, hence why I wrote my own. But now I’m unsure.

My issue (and this is sort of off topic) is that I’m actually trying to package this as a pip installable package on pypi. I have python bindings that pull up a UI for hunting down GPU memory leaks. I can’t write it completely in python using the bindings because I’m trying to render hundreds of thousands of nodes in real time.

I thought that the solution would be to use pysdl2-dll. But when I went to use it, I realized two things. First, that I have no idea how python packaging works. Second, that it doesn’t actually come with any headers. It has the shared libraries that I need for linking, but not the symbols or macros. Seems like a dead end.

So… got any ideas? I could build SDL3 from source and just use the included file picker. But in that case, how do I create a platform independent build script? Should I attempt to download SDL3 and use cmake to compile it from the setup.py? Is there a guide anywhere? I’m in the unfortunate position of not knowing how to use cmake, and having never packaged system-level dependencies into a python package before.

My issue (and this is sort of off topic) is that I’m actually trying to package this as a pip installable package on pypi.

Well, I can’t say that’s the right choice of tool, it is for python packages, although you can stuff whatever you want in there.

I thought that the solution would be to use pysdl2-dll.

I believe this package is just for things like FFI. The thing you need:

but not the symbols or macros. Seems like a dead end.

They should come from system installed dependencies.
Python’s way is to provide prebuilds for most popular platforms, and if there’s no match for the end user, then compile the program. The latter almost always means using system-installed libraries, and it could fail if the user doesn’t have developer packages installed. You can show message like “Compilation failed make sure you installed libsdl2-dev”. It is also correct to assume that end users will have libABC installed if they want to use compiled python-libABC.

how do I create a platform independent build script? Should I attempt to download SDL3 and use cmake to compile it from the setup.py? Is there a guide anywhere?

This is certainly a hell of a rabbit hole :grin:, and you have countless ways to deal with it.
For your program, I will recommend that you only depend on the libraries installed in the system, since you only have one external dependency, libsdl.

I will not advise you to try SDL3 until it is finally released (which will be really soon btw!) as not every Linux disto package it, on the other hand SDL2 is available pretty much everywhere.

If you plan to support windows, then prebuilds are the thing, as the package management there is a wild west.

It will probably be better if you ship an AppImage of your application instead of a python package. The things you want to do are possible, but honestly very annoying.