Skip to content

Commit

Permalink
Attempt to fix VITURE crash
Browse files Browse the repository at this point in the history
  • Loading branch information
wheaney committed Jan 7, 2024
1 parent af2a81f commit 69193a8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
1 change: 0 additions & 1 deletion bin/xreal_driver_config
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ then
elif [ "$1" == "--sbs-mode-stretched" ] || [ "$1" == "-sbsms" ]; then
config_type="string"
config_key="sbs_mode_stretched"
# use $2 if present, otherwise default to "true"
config_value="${2:-true}"
elif [ "$1" == "--sbs-content-3d" ] || [ "$1" == "-sbs3d" ]; then
config_type="string"
Expand Down
25 changes: 25 additions & 0 deletions src/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

#include <dirent.h>
#include <errno.h>
#include <execinfo.h>
#include <fcntl.h>
#include <inttypes.h>
#include <libgen.h>
#include <limits.h>
#include <math.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -144,6 +146,7 @@ void *block_on_device_thread_func(void *arg) {
free_and_clear(&state()->connected_device_brand);
free_and_clear(&state()->connected_device_model);
}
free(context.device);
context.device = NULL;

if (ipc_enabled) *ipc_values->disabled = true;
Expand Down Expand Up @@ -384,7 +387,29 @@ bool search_for_device() {
return false;
}

void segfault_handler(int signal, siginfo_t *si, void *arg)
{
void *error_addr = si->si_addr;

// Write the error address to stderr
fprintf(stderr, "Segmentation fault occurred at address: %p\n", error_addr);

// Write the backtrace to stderr
void *buffer[10];
int nptrs = backtrace(buffer, 10);
backtrace_symbols_fd(buffer, nptrs, 2);

// End the process
exit(EXIT_FAILURE);
}

int main(int argc, const char** argv) {
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = segfault_handler;
sigemptyset(&sa.sa_mask);
sigaction(SIGSEGV, &sa, NULL);

context.config = default_config();
config_fp = get_or_create_home_file(".xreal_driver_config", "r", &config_filename[0], NULL);
update_config_from_file(config_fp);
Expand Down
24 changes: 13 additions & 11 deletions src/viture.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void viture_mcu_callback(uint16_t msgid, uint8_t *data, uint16_t len, uint32_t t
}

device_properties_type* viture_device_connect() {
bool alreadyConnected = get_imu_state() == ERR_SUCCESS;
bool alreadyConnected = get_imu_state() == STATE_ON;

bool success = alreadyConnected || init(handle_viture_event, viture_mcu_callback);
if (success) {
Expand All @@ -135,20 +135,22 @@ device_properties_type* viture_device_connect() {
// device may not support this frequency, re-query it below
set_imu_fq(IMU_FREQUENCE_240);

device_properties_type* device = malloc(sizeof(device_properties_type));
*device = viture_one_properties;
if (get_imu_fq() >= IMU_FREQUENCE_60 && get_imu_fq() <= IMU_FREQUENCE_240) {
device_properties_type* device = malloc(sizeof(device_properties_type));
*device = viture_one_properties;

// use the current value in case the frequency we requested isn't supported
device->imu_cycles_per_s = frequency_enum_to_value[get_imu_fq()];
device->imu_buffer_size = (int) device->imu_cycles_per_s / 60;
// use the current value in case the frequency we requested isn't supported
device->imu_cycles_per_s = frequency_enum_to_value[get_imu_fq()];
device->imu_buffer_size = (int) device->imu_cycles_per_s / 60;

// not a great way to check the firmware version but it's all we have
old_firmware_version = device->imu_cycles_per_s == 60;
// not a great way to check the firmware version but it's all we have
old_firmware_version = device->imu_cycles_per_s == 60;

device->sbs_mode_supported = !old_firmware_version;
device->firmware_update_recommended = old_firmware_version;
device->sbs_mode_supported = !old_firmware_version;
device->firmware_update_recommended = old_firmware_version;

return device;
return device;
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/xreal.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ void xreal_block_on_device() {
pthread_join(controller_thread, NULL);

free(context.device->model);
free(context.device);
};

int get_display_mode_index(int display_mode, const int* display_modes) {
Expand Down

0 comments on commit 69193a8

Please sign in to comment.