Fix segfaults on device specific config files
This commit is contained in:
parent
c3a88f3b07
commit
88db6c5f04
|
|
@ -31,6 +31,7 @@ struct SimDevice
|
||||||
int fps;
|
int fps;
|
||||||
bool initialized;
|
bool initialized;
|
||||||
lua_State* L;
|
lua_State* L;
|
||||||
|
char* device_specific_config_file;
|
||||||
DeviceType type;
|
DeviceType type;
|
||||||
HapticEffect hapticeffect;
|
HapticEffect hapticeffect;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,6 @@ int cammusc12_init(USBDevice* wheeldevice, const char* luafile)
|
||||||
int res = cammusc12_init_(wheeldevice);
|
int res = cammusc12_init_(wheeldevice);
|
||||||
if(luafile == NULL)
|
if(luafile == NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,10 @@ int wheeldev_free(USBDevice* usbdevice)
|
||||||
break;
|
break;
|
||||||
case WHEELDEV_CAMMUSC12 :
|
case WHEELDEV_CAMMUSC12 :
|
||||||
cammusc12_update(usbdevice, 0, 0, 0, 0);
|
cammusc12_update(usbdevice, 0, 0, 0, 0);
|
||||||
|
if(usbdevice->m.device_specific_config_file != NULL)
|
||||||
|
{
|
||||||
|
free(usbdevice->m.device_specific_config_file);
|
||||||
|
}
|
||||||
cammusc12_free(usbdevice);
|
cammusc12_free(usbdevice);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +78,8 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
||||||
|
|
||||||
if(ds->has_config == true)
|
if(ds->has_config == true)
|
||||||
{
|
{
|
||||||
error = cammusc12_init(usbdevice, ds->specific_config_file);
|
usbdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||||
|
error = cammusc12_init(usbdevice, usbdevice->m.device_specific_config_file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -237,13 +237,13 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||||
slogi("looking for ui config %s pass 3", ms->config_str);
|
slogi("looking for ui config %s pass 3", ms->config_str);
|
||||||
confignum = getconfigtouse(ms->config_str, simdata->car, f->sim);
|
confignum = getconfigtouse(ms->config_str, simdata->car, f->sim);
|
||||||
}
|
}
|
||||||
|
|
||||||
int configureddevices;
|
int configureddevices;
|
||||||
configcheck(ms->config_str, confignum, &configureddevices);
|
configcheck(ms->config_str, confignum, &configureddevices);
|
||||||
|
|
||||||
DeviceSettings* ds = malloc(configureddevices * sizeof(DeviceSettings));
|
DeviceSettings* ds = malloc(configureddevices * sizeof(DeviceSettings));
|
||||||
slogd("loading confignum %i, with %i devices.", confignum, configureddevices);
|
slogd("loading confignum %i, with %i devices.", confignum, configureddevices);
|
||||||
|
|
||||||
f->numdevices = uiloadconfig(ms->config_str, confignum, configureddevices, ms, ds);
|
f->numdevices = uiloadconfig(ms->config_str, confignum, configureddevices, ms, ds);
|
||||||
|
|
||||||
if(ms->useconfig == 1)
|
if(ms->useconfig == 1)
|
||||||
{
|
{
|
||||||
ms->configcheck = 0;
|
ms->configcheck = 0;
|
||||||
|
|
@ -251,12 +251,7 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||||
|
|
||||||
f->simdevices = malloc(f->numdevices * sizeof(SimDevice));
|
f->simdevices = malloc(f->numdevices * sizeof(SimDevice));
|
||||||
int initdevices = devinit(f->simdevices, configureddevices, ds, ms);
|
int initdevices = devinit(f->simdevices, configureddevices, ds, ms);
|
||||||
int i = 0;
|
|
||||||
for( i = 0; i < configureddevices; i++)
|
|
||||||
{
|
|
||||||
settingsfree(ds[i]);
|
|
||||||
}
|
|
||||||
free(ds);
|
|
||||||
|
|
||||||
|
|
||||||
for(int d = 0; d < 10; d++)
|
for(int d = 0; d < 10; d++)
|
||||||
|
|
@ -285,10 +280,21 @@ void looprun(MonocoqueSettings* ms, loop_data* f, SimData* simdata)
|
||||||
uv_handle_set_data((uv_handle_t*) dt, (void*) dld);
|
uv_handle_set_data((uv_handle_t*) dt, (void*) dld);
|
||||||
int interval = 1000/devices[x].fps;
|
int interval = 1000/devices[x].fps;
|
||||||
uv_timer_start(dt, devicetimercallback, 0, interval);
|
uv_timer_start(dt, devicetimercallback, 0, interval);
|
||||||
slogi("starting device at %i fps (%i ms ticks)", devices[x].fps, interval);
|
slogi("starting device type %i at id at %i fps (%i ms ticks)", devices[x].type, x, devices[x].fps, interval);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slogw("skipped id %i of type %i", x, devices[x].type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for( i = 0; i < configureddevices; i++)
|
||||||
|
{
|
||||||
|
settingsfree(ds[i]);
|
||||||
|
}
|
||||||
|
free(ds);
|
||||||
|
|
||||||
doui = false;
|
doui = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -712,16 +712,19 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
|
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
|
||||||
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
||||||
|
|
||||||
const char* temp;
|
const char* temp = NULL;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
found = config_setting_lookup_string(device_settings, "devid", &temp);
|
found = config_setting_lookup_string(device_settings, "devid", &temp);
|
||||||
if (found == 0)
|
if (found == CONFIG_FALSE)
|
||||||
{
|
{
|
||||||
ds->sounddevsettings.dev = NULL;
|
ds->sounddevsettings.dev = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ds->sounddevsettings.dev = strdup(temp);
|
if(temp != NULL)
|
||||||
|
{
|
||||||
|
ds->sounddevsettings.dev = strdup(temp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -808,17 +811,23 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
ds->has_config = false;
|
ds->has_config = false;
|
||||||
const char* temp2;
|
const char* temp2;
|
||||||
int found = config_setting_lookup_string(device_settings, "config", &temp2);
|
int found = config_setting_lookup_string(device_settings, "config", &temp2);
|
||||||
if(strcicmp(temp2, "none") == 0 || found == 0)
|
if(found == 0)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "Here?");
|
||||||
slogt("config set to none");
|
slogt("config set to none");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ds->has_config = true;
|
ds->has_config = true;
|
||||||
ds->specific_config_file = strdup(temp2);
|
ds->specific_config_file = strdup(temp2);
|
||||||
|
if(strcicmp(temp2, "none") == 0)
|
||||||
|
{
|
||||||
|
ds->has_config = false;
|
||||||
|
free(ds->specific_config_file);
|
||||||
|
ds->specific_config_file = NULL;
|
||||||
|
}
|
||||||
slogt("will try to load config file at %s", ds->specific_config_file);
|
slogt("will try to load config file at %s", ds->specific_config_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -852,17 +861,17 @@ int uiloadconfig(const char* config_file_str, int confignum, int configureddevic
|
||||||
config_setting_t* config_device = config_setting_get_elem(config_devices, i);
|
config_setting_t* config_device = config_setting_get_elem(config_devices, i);
|
||||||
const char* device_type;
|
const char* device_type;
|
||||||
const char* device_subtype;
|
const char* device_subtype;
|
||||||
const char* device_config_file;
|
//const char* device_config_file;
|
||||||
config_setting_lookup_string(config_device, "device", &device_type);
|
config_setting_lookup_string(config_device, "device", &device_type);
|
||||||
config_setting_lookup_string(config_device, "type", &device_subtype);
|
config_setting_lookup_string(config_device, "type", &device_subtype);
|
||||||
config_setting_lookup_string(config_device, "config", &device_config_file);
|
//config_setting_lookup_string(config_device, "config", &device_config_file);
|
||||||
|
|
||||||
//slogt("device type: %s", device_type);
|
//slogt("device type: %s", device_type);
|
||||||
//slogt("device sub type: %s", device_subtype);
|
//slogt("device sub type: %s", device_subtype);
|
||||||
//slogt("device config file: %s", device_config_file);
|
//slogt("device config file: %s", device_config_file);
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
error = devsetup(device_type, device_subtype, device_config_file, ms, &settings, config_device);
|
error = devsetup(device_type, device_subtype, NULL, ms, &settings, config_device);
|
||||||
}
|
}
|
||||||
if (error == MONOCOQUE_ERROR_NONE)
|
if (error == MONOCOQUE_ERROR_NONE)
|
||||||
{
|
{
|
||||||
|
|
@ -900,6 +909,11 @@ int settingsfree(DeviceSettings ds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ds.has_config && ds.specific_config_file != NULL)
|
||||||
|
{
|
||||||
|
free(ds.specific_config_file);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue