[simulation] Fix some potential crashes & 26 memory leaks, improve LCD redraws. (#4634)

* [simulation] Hardening: Fix some potential crashes & 26 memory leaks, improve LCD performance.
  * [simpgmspace] Init trims; Make sure `REa` is really defined (to match board files).
  * [simpgmspace][opentxsimulator] Verify current running state before start/stop; Move rotary enc. init.
  * [simpgmspace][LcdWidget] Improve performance by moving LCD content change check to lcdRefresh() & limiting LcdWidget refresh time to 60 fps max.
  * [simueeprom] Ensure thread could be started, set default running state to false.
  * [simufatfs] Fix paths report trace.
  * [eepromimportexport] Fix memory leaks resulting from import debugging scheme being used.
  * [customdebug] Introduce new scheme for custom debug output in compliance with Qt recommendations (see docs for QLoggingCategory).
  * [opentxeeprom] Fix extra conversion table cache elements being created and also not properly deleted (and hence leaking).
  * [opentxinterface] Unregister EEpromInterfaces in unregisterOpenTxFirmwares();
  * [storage] Unregister storage factories on exit (fixes leak); create virtual StorageFormat/StorageFactory destructors (prevents warnings).
  * [helpers] GVarGroup now emits own signal, no need to pass ModelPanel pointer (removes dependency on modeledit.h)
  * [DebugOutput] Clear simulator trace hook before exiting (prevent possible issues); Fix leak and possible bad QString allocations when reading from buffer; Fix leak with combo box event filter.
  * [TelemetrySimulator] Fix leak by deleting LogPlaybackController object on exit; Only set up data fields once; convert timers to static.
  * [build] Consolidate all Companion/Simulator shared items in `common` library to reduce build time/etc (node & edge still remain awkward).

* [simulatorwidget] Delete removed spacer object (previously-forgotten "26th" leak).

* [DebugOutput] Fix stray trailing characters issue with new text buffer allocation (from previous commit); Increase maximum buffer sizes to better accommodate slower systems.

* Cosmetics.
This commit is contained in:
Max Paperno
2017-03-21 07:43:40 +01:00
committed by Bertrand Songis
parent 52e65179a8
commit 4aa0c1bbe4
28 changed files with 290 additions and 210 deletions
+27 -14
View File
@@ -64,6 +64,12 @@ void registerStorageFactories()
registerStorageFactory(new SdcardStorageFactory());
}
void unregisterStorageFactories()
{
foreach (StorageFactory * factory, registeredStorageFactories)
delete factory;
}
bool Storage::load(RadioData & radioData)
{
QFile file(filename);
@@ -71,30 +77,37 @@ bool Storage::load(RadioData & radioData)
setError(QObject::tr("Unable to find file %1!").arg(filename));
return false;
}
bool ret = false;
foreach(StorageFactory * factory, registeredStorageFactories) {
StorageFormat * format = factory->instance(filename);
if (format->load(radioData)) {
board = format->getBoard();
setWarning(format->warning());
return true;
ret = true;
break;
}
else {
setError(format->error());
}
delete format;
}
return false;
return ret;
}
bool Storage::write(const RadioData & radioData)
{
bool ret = false;
foreach(StorageFactory * factory, registeredStorageFactories) {
if (factory->probe(filename)) {
return factory->instance(filename)->write(radioData);
StorageFormat * format = factory->instance(filename);
ret = format->write(radioData);
delete format;
break;
}
}
return false;
return ret;
}
bool convertEEprom(const QString & sourceEEprom, const QString & destinationEEprom, const QString & firmwareFilename)
@@ -102,26 +115,26 @@ bool convertEEprom(const QString & sourceEEprom, const QString & destinationEEpr
FirmwareInterface firmware(firmwareFilename);
if (!firmware.isValid())
return false;
uint8_t version = firmware.getEEpromVersion();
unsigned int variant = firmware.getEEpromVariant();
QSharedPointer<RadioData> radioData = QSharedPointer<RadioData>(new RadioData());
Storage storage(sourceEEprom);
if (!storage.load(*radioData))
return false;
QByteArray eeprom(EESIZE_MAX, 0);
int size = getCurrentEEpromInterface()->save((uint8_t *)eeprom.data(), *radioData, version, variant);
if (size == 0) {
return false;
}
QFile destinationFile(destinationEEprom);
if (!destinationFile.open(QIODevice::WriteOnly)) {
return false;
}
int result = destinationFile.write(eeprom.constData(), size);
destinationFile.close();
return (result == size);
@@ -131,7 +144,7 @@ bool convertEEprom(const QString & sourceEEprom, const QString & destinationEEpr
unsigned long LoadBackup(RadioData & radioData, uint8_t * eeprom, int size, int index)
{
std::bitset<NUM_ERRORS> errors;
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
std::bitset<NUM_ERRORS> result((unsigned long long)eepromInterface->loadBackup(radioData, eeprom, size, index));
if (result.test(ALL_OK)) {
@@ -141,7 +154,7 @@ unsigned long LoadBackup(RadioData & radioData, uint8_t * eeprom, int size, int
errors |= result;
}
}
if (errors.none()) {
errors.set(UNKNOWN_ERROR);
}
@@ -152,7 +165,7 @@ unsigned long LoadBackup(RadioData & radioData, uint8_t * eeprom, int size, int
unsigned long LoadEepromXml(RadioData & radioData, QDomDocument & doc)
{
std::bitset<NUM_ERRORS> errors;
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
std::bitset<NUM_ERRORS> result((unsigned long long)eepromInterface->loadxml(radioData, doc));
if (result.test(ALL_OK)) {
@@ -162,7 +175,7 @@ unsigned long LoadEepromXml(RadioData & radioData, QDomDocument & doc)
errors |= result;
}
}
if (errors.none()) {
errors.set(UNKNOWN_ERROR);
}