@@ -12,6 +12,7 @@ struct Driver; | |||||
static const int DRIVER = -10; | static const int DRIVER = -10; | ||||
static Driver* driver = NULL; | |||||
struct InputDevice : midi::InputDevice { | struct InputDevice : midi::InputDevice { | ||||
@@ -116,17 +117,17 @@ struct Driver : midi::Driver { | |||||
}; | }; | ||||
static Driver driver; | |||||
void init() { | void init() { | ||||
midi::addDriver(DRIVER, &driver); | |||||
driver = new Driver; | |||||
midi::addDriver(DRIVER, driver); | |||||
} | } | ||||
void step() { | void step() { | ||||
for (int i = 0; i < 16; i++) { | for (int i = 0; i < 16; i++) { | ||||
if (glfwJoystickPresent(i)) { | if (glfwJoystickPresent(i)) { | ||||
driver.devices[i].step(); | |||||
driver->devices[i].step(); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -265,15 +265,15 @@ json_t* PatchManager::toJson() { | |||||
json_t* versionJ = json_string(APP_VERSION.c_str()); | json_t* versionJ = json_string(APP_VERSION.c_str()); | ||||
json_object_set_new(rootJ, "version", versionJ); | json_object_set_new(rootJ, "version", versionJ); | ||||
json_t* engineJ = APP->engine->toJson(); | |||||
if (APP->scene) { | |||||
APP->scene->rack->mergeJson(engineJ); | |||||
} | |||||
// Merge with rootJ | // Merge with rootJ | ||||
json_t* engineJ = APP->engine->toJson(); | |||||
json_object_update(rootJ, engineJ); | json_object_update(rootJ, engineJ); | ||||
json_decref(engineJ); | json_decref(engineJ); | ||||
if (APP->scene) { | |||||
APP->scene->rack->mergeJson(rootJ); | |||||
} | |||||
return rootJ; | return rootJ; | ||||
} | } | ||||
@@ -242,18 +242,18 @@ void init() { | |||||
void destroy() { | void destroy() { | ||||
for (Plugin* plugin : plugins) { | for (Plugin* plugin : plugins) { | ||||
// We must delete the plugin *before* freeing the library, because the vtable of Model subclasses are static in the plugin, and we need it for the virtual destructor. | |||||
void* handle = plugin->handle; | |||||
delete plugin; | |||||
// Free library handle | // Free library handle | ||||
if (plugin->handle) { | |||||
if (handle) { | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
FreeLibrary((HINSTANCE) plugin->handle); | |||||
FreeLibrary((HINSTANCE) handle); | |||||
#else | #else | ||||
dlclose(plugin->handle); | |||||
dlclose(handle); | |||||
#endif | #endif | ||||
} | } | ||||
// For some reason this segfaults. | |||||
// It might be best to let them leak anyway, because "crash on exit" issues would occur with badly-written plugins. | |||||
// delete plugin; | |||||
} | } | ||||
plugins.clear(); | plugins.clear(); | ||||
} | } | ||||