Skip to content

Commit 27122d4

Browse files
committed
fix segmentation fault when --led-emulator is set via command line
1 parent a05c2fa commit 27122d4

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

CMakeLists.txt

+16-13
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ set(MATRIX_SOURCES ${MATRIX_CORE_SOURCES})
2929
if(ENABLE_EMULATOR)
3030
# Add emulator source
3131
list(APPEND MATRIX_SOURCES lib/emulator.cc)
32-
33-
# Find SDL2 for the emulator
34-
find_package(SDL2 REQUIRED)
35-
36-
# Define preprocessor macro to indicate emulator is enabled
37-
add_compile_definitions(ENABLE_EMULATOR)
38-
32+
3933
message(STATUS "Building with emulator support")
4034
else()
4135
message(STATUS "Building without emulator support")
@@ -49,11 +43,20 @@ target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
4943
# Include directories
5044
target_include_directories(${PROJECT_NAME}
5145
PRIVATE
52-
# where the library itself will look for its internal headers
53-
${CMAKE_CURRENT_SOURCE_DIR}/lib
46+
# where the library itself will look for its internal headers
47+
${CMAKE_CURRENT_SOURCE_DIR}/lib
5448
PUBLIC
55-
# where top-level project will look for the library's public headers
56-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
57-
# where external projects will look for the library's public headers
58-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
49+
# where top-level project will look for the library's public headers
50+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
51+
# where external projects will look for the library's public headers
52+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
5953
)
54+
55+
# Export ENABLE_EMULATOR define to consumers of the library
56+
if(ENABLE_EMULATOR)
57+
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_EMULATOR)
58+
59+
# Find SDL2 for the emulator
60+
find_package(SDL2 REQUIRED)
61+
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2)
62+
endif()

examples/emulator-demo.cc

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ int main(int argc, char *argv[]) {
5050
options.led_options.chain_length = 2;
5151
options.led_options.parallel = 2;
5252
options.led_options.hardware_mapping = "regular"; // Add this line to ensure hardware mapping is set
53-
options.use_emulator = true;
5453
options.emulator_options.display_scale = 5; // Larger window for emulator
5554
options.emulator_options.window_title = "LED Matrix Emulator Demo";
5655

include/matrix-factory.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
#define RPI_RGBMATRIX_FACTORY_H
1818

1919
#include "led-matrix.h"
20+
21+
// Only include emulator.h when emulator support is enabled
22+
#ifdef ENABLE_EMULATOR
2023
#include "emulator.h"
24+
#endif
2125

2226
namespace rgb_matrix {
2327

@@ -38,7 +42,6 @@ class MatrixFactory {
3842
// Runtime options specific to the hardware matrix
3943
RuntimeOptions runtime_options;
4044

41-
4245
#ifdef ENABLE_EMULATOR
4346
// Options specific to the emulator
4447
EmulatorOptions emulator_options;

lib/matrix-factory.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ namespace rgb_matrix
6969
options->use_emulator = true;
7070
if (remove_consumed_flags)
7171
{
72-
(*argv)[i] = nullptr;
72+
// Very unclean way of doing this, but it works
73+
(*argv)[i] = "";
7374
}
7475
}
7576
}

0 commit comments

Comments
 (0)