Segmentation fault since migration to JUCE v5


#1

Hi experts,

I got some troubles, I can’t run any of my previous in-house projects since the v5 upgrade.
It creates each time a segmentation fault at the following instruction :

juce::StringArray result = juce::MidiInput::getDevices();

I can’t understand why :frowning: Juce Demos are working fine… I run a debian 8
Here’s the gdb bt output (though not very insightfull) :

Core was generated by `./usynth’.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000465d7b in ?? ()
(gdb) bt
#0 0x0000000000465d7b in ?? ()
#1 0x00007ffc38343b40 in ?? ()
#2 0x00000000020ae1b0 in ?? ()
#3 0x0000000000000000 in ?? ()
(gdb)

Any help very much appreciate


#2

Can you create a very basic app which crashes in the same way? I’m afraid that without more information we’re not going to be able to help very much.


#3

Zeros are never good :slight_smile:


#4

Is that the WHOLE backtrace?

If so, maybe you’ve overwritten your stack…

Are you on linux?


#5

Full code sample :

#include “…/JuceLibraryCode/JuceHeader.h”
#include

int main (int argc, char* argv[])
{
std::cout << “Starting” << std::endl;
juce::StringArray devices = juce::MidiInput::getDevices(); // Explode here !
std::cout << “Still alive ?” << std::endl;

for (auto item : devices)
{
std::cout << "Found device = " << item << std::endl;
}

return 0;
}

Linux make file :

Automatically generated makefile, created by the Projucer

Don’t edit this file! Your changes will be overwritten when you re-save the Projucer project!

build with “V=1” for verbose builds

ifeq ($(V), 1)
V_AT =
else
V_AT = @
endif

(this disables dependency generation if multiple architectures are set)

DEPFLAGS := (if (word 2, $(TARGET_ARCH)), , -MMD)

ifndef STRIP
STRIP=strip
endif

ifndef AR
AR=ar
endif

ifndef CONFIG
CONFIG=Debug
endif

ifeq ($(CONFIG),Debug)
JUCE_BINDIR := build
JUCE_LIBDIR := build
JUCE_OBJDIR := build/intermediate/Debug
JUCE_OUTDIR := build

ifeq ($(TARGET_ARCH),)
TARGET_ARCH := -march=native
endif

JUCE_CPPFLAGS := (DEPFLAGS) -DLINUX=1 -DDEBUG=1 -D_DEBUG=1 -DJUCER_LINUX_MAKE_6D53C8B4=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 (shell pkg-config --cflags alsa freetype2 libcurl x11 xext xinerama webkit2gtk-4.0 gtk±x11-3.0) -pthread -I…/…/JuceLibraryCode -I/home/sam/library/JUCE/modules $(CPPFLAGS)
JUCE_CPPFLAGS_CONSOLEAPP := -DJucePlugin_Build_VST=0 -DJucePlugin_Build_VST3=0 -DJucePlugin_Build_AU=0 -DJucePlugin_Build_AUv3=0 -DJucePlugin_Build_RTAS=0 -DJucePlugin_Build_AAX=0 -DJucePlugin_Build_Standalone=0
JUCE_TARGET_CONSOLEAPP := Juce5POC

JUCE_CFLAGS += (JUCE_CPPFLAGS) (TARGET_ARCH) -g -ggdb -O0 (CFLAGS) JUCE_CXXFLAGS += (CXXFLAGS) (JUCE_CFLAGS) -std=c++11 (CXXFLAGS)
JUCE_LDFLAGS += (TARGET_ARCH) -L(JUCE_BINDIR) -L$(JUCE_LIBDIR) (shell pkg-config --libs alsa freetype2 libcurl x11 xext xinerama webkit2gtk-4.0 gtk+-x11-3.0) -lGL -ldl -lpthread -lrt (LDFLAGS)

CLEANCMD = rm -rf (JUCE_OUTDIR)/(TARGET) $(JUCE_OBJDIR)
endif

ifeq ($(CONFIG),Release)
JUCE_BINDIR := build
JUCE_LIBDIR := build
JUCE_OBJDIR := build/intermediate/Release
JUCE_OUTDIR := build

ifeq ($(TARGET_ARCH),)
TARGET_ARCH := -march=native
endif

JUCE_CPPFLAGS := (DEPFLAGS) -DLINUX=1 -DNDEBUG=1 -DJUCER_LINUX_MAKE_6D53C8B4=1 -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 (shell pkg-config --cflags alsa freetype2 libcurl x11 xext xinerama webkit2gtk-4.0 gtk±x11-3.0) -pthread -I…/…/JuceLibraryCode -I/home/sam/library/JUCE/modules $(CPPFLAGS)
JUCE_CPPFLAGS_CONSOLEAPP := -DJucePlugin_Build_VST=0 -DJucePlugin_Build_VST3=0 -DJucePlugin_Build_AU=0 -DJucePlugin_Build_AUv3=0 -DJucePlugin_Build_RTAS=0 -DJucePlugin_Build_AAX=0 -DJucePlugin_Build_Standalone=0
JUCE_TARGET_CONSOLEAPP := Juce5POC

JUCE_CFLAGS += (JUCE_CPPFLAGS) (TARGET_ARCH) -O3 (CFLAGS) JUCE_CXXFLAGS += (CXXFLAGS) (JUCE_CFLAGS) -std=c++11 (CXXFLAGS)
JUCE_LDFLAGS += (TARGET_ARCH) -L(JUCE_BINDIR) -L$(JUCE_LIBDIR) -fvisibility=hidden (shell pkg-config --libs alsa freetype2 libcurl x11 xext xinerama webkit2gtk-4.0 gtk+-x11-3.0) -lGL -ldl -lpthread -lrt (LDFLAGS)

CLEANCMD = rm -rf (JUCE_OUTDIR)/(TARGET) $(JUCE_OBJDIR)
endif

OBJECTS_CONSOLEAPP :=
(JUCE_OBJDIR)/Main_90ebc5c2.o \ (JUCE_OBJDIR)/include_juce_audio_basics_8a4e984a.o
(JUCE_OBJDIR)/include_juce_audio_devices_63111d02.o \ (JUCE_OBJDIR)/include_juce_audio_formats_15f82001.o
(JUCE_OBJDIR)/include_juce_audio_processors_10c03666.o \ (JUCE_OBJDIR)/include_juce_core_f26d17db.o
(JUCE_OBJDIR)/include_juce_cryptography_8cb807a8.o \ (JUCE_OBJDIR)/include_juce_data_structures_7471b1e3.o
(JUCE_OBJDIR)/include_juce_events_fd7d695.o \ (JUCE_OBJDIR)/include_juce_graphics_f817e147.o
(JUCE_OBJDIR)/include_juce_gui_basics_e3f79785.o \ (JUCE_OBJDIR)/include_juce_gui_extra_6dee1c1a.o
(JUCE_OBJDIR)/include_juce_opengl_a8a032b.o \ (JUCE_OBJDIR)/include_juce_video_be78589.o \

.PHONY: clean all

all : (JUCE_OUTDIR)/(JUCE_TARGET_CONSOLEAPP)

(JUCE_OUTDIR)/(JUCE_TARGET_CONSOLEAPP) : check-pkg-config (OBJECTS_CONSOLEAPP) (RESOURCES)
@echo Linking “Juce5POC - ConsoleApp”
-(V_AT)mkdir -p (JUCE_BINDIR)
-(V_AT)mkdir -p (JUCE_LIBDIR)
-(V_AT)mkdir -p (JUCE_OUTDIR)
(V_AT)(CXX) -o (JUCE_OUTDIR)/(JUCE_TARGET_CONSOLEAPP) (OBJECTS_CONSOLEAPP) (JUCE_LDFLAGS) (RESOURCES) (TARGET_ARCH)

(JUCE_OBJDIR)/Main_90ebc5c2.o: ../../Source/Main.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling Main.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_audio_basics_8a4e984a.o: ../../JuceLibraryCode/include_juce_audio_basics.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_audio_basics.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_audio_devices_63111d02.o: ../../JuceLibraryCode/include_juce_audio_devices.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_audio_devices.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_audio_formats_15f82001.o: ../../JuceLibraryCode/include_juce_audio_formats.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_audio_formats.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_audio_processors_10c03666.o: ../../JuceLibraryCode/include_juce_audio_processors.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_audio_processors.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_core_f26d17db.o: ../../JuceLibraryCode/include_juce_core.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_core.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_cryptography_8cb807a8.o: ../../JuceLibraryCode/include_juce_cryptography.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_cryptography.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_data_structures_7471b1e3.o: ../../JuceLibraryCode/include_juce_data_structures.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_data_structures.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_events_fd7d695.o: ../../JuceLibraryCode/include_juce_events.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_events.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_graphics_f817e147.o: ../../JuceLibraryCode/include_juce_graphics.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_graphics.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_gui_basics_e3f79785.o: ../../JuceLibraryCode/include_juce_gui_basics.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_gui_basics.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_gui_extra_6dee1c1a.o: ../../JuceLibraryCode/include_juce_gui_extra.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_gui_extra.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_opengl_a8a032b.o: ../../JuceLibraryCode/include_juce_opengl.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_opengl.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

(JUCE_OBJDIR)/include_juce_video_be78589.o: ../../JuceLibraryCode/include_juce_video.cpp -(V_AT)mkdir -p (JUCE_OBJDIR) @echo "Compiling include_juce_video.cpp" (V_AT)(CXX) (JUCE_CXXFLAGS) (JUCE_CPPFLAGS_CONSOLEAPP) (JUCE_CFLAGS_CONSOLEAPP) -o “@" -c "<”

check-pkg-config:
@command -v pkg-config >/dev/null 2>&1 || { echo >&2 “pkg-config not installed. Please, install it.”; exit 1; }
@pkg-config --print-errors alsa freetype2 libcurl x11 xext xinerama

clean:
@echo Cleaning Juce5POC
(V_AT)(CLEANCMD)

strip:
@echo Stripping Juce5POC
-(V_AT)(STRIP) --strip-unneeded (JUCE_OUTDIR)/(TARGET)

-include $(OBJECTS_CONSOLEAPP:%.o=%.d)


#6

If you indent all the lines of code by four spaces then it will get formatted automatically by this forum.

As it stands the Linux MIDI classes are expecting you to have set up an application via JUCEApplicationBase so that JUCE’s event loop is configured - which lets you do things like send and receive MIDI messages. If you look here

you can see that if JUCE_ALSA_MIDI_NAME is not defined then JUCE attempts to get your application name from JUCEApplicationBase, which is unlikely to be successful in your case.

Try adding

#define JUCE_ALSA_MIDI_NAME "YourAppName"

to the user code section of AppConfig.h.


#7

Thanks a lot for your answer but what if my application is console based ?

It worked like a charm with Juce 4.3


#8

YES !!! It works now I change the main.cpp instead of the AppConfig.h :frowning:

==> Thanks a lot :slight_smile:

AMHA : it is anyway a breaking change… Meaning not needed in Juce 4.3 (no offense).
I’m still very happy with the Juce library !-)