mirror of
https://github.com/love2d/love.git
synced 2026-08-21 21:15:09 +02:00
fixed potential memory leak, minor code imporovements
--HG-- branch : minor-mic-input
This commit is contained in:
@@ -120,8 +120,8 @@ Audio::Audio()
|
|||||||
alcMakeContextCurrent(nullptr);
|
alcMakeContextCurrent(nullptr);
|
||||||
alcDestroyContext(context);
|
alcDestroyContext(context);
|
||||||
alcCloseDevice(device);
|
alcCloseDevice(device);
|
||||||
for (unsigned int i = 0; i < capture.size(); i++)
|
for (auto c : capture)
|
||||||
delete capture[i];
|
delete c;
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
@@ -141,8 +141,8 @@ Audio::~Audio()
|
|||||||
alcMakeContextCurrent(nullptr);
|
alcMakeContextCurrent(nullptr);
|
||||||
alcDestroyContext(context);
|
alcDestroyContext(context);
|
||||||
alcCloseDevice(device);
|
alcCloseDevice(device);
|
||||||
for (unsigned int i = 0; i < capture.size(); i++)
|
for (auto c : capture)
|
||||||
delete capture[i];
|
delete c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -337,6 +337,8 @@ const std::vector<love::audio::RecordingDevice*> &Audio::getRecordingDevices()
|
|||||||
return capture;
|
return capture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devnames.reserve(capture.size());
|
||||||
devnames.push_back(defaultname);
|
devnames.push_back(defaultname);
|
||||||
|
|
||||||
//find devices name list
|
//find devices name list
|
||||||
@@ -352,20 +354,29 @@ const std::vector<love::audio::RecordingDevice*> &Audio::getRecordingDevices()
|
|||||||
offset += str.length() + 1;
|
offset += str.length() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//build list of devices
|
|
||||||
devices.reserve(devnames.size());
|
devices.reserve(devnames.size());
|
||||||
|
//build ordered list of devices
|
||||||
for (unsigned int i = 0; i < devnames.size(); i++)
|
for (unsigned int i = 0; i < devnames.size(); i++)
|
||||||
{
|
{
|
||||||
devices[i] = nullptr;
|
devices.push_back(nullptr);
|
||||||
for (auto c = capture.begin(); c != capture.end(); c++)
|
auto d = devices.end() - 1;
|
||||||
if (devnames[i] == (*c)->getName())
|
|
||||||
devices[i] = *c;
|
|
||||||
|
|
||||||
if (devices[i] == nullptr)
|
for (auto c : capture)
|
||||||
devices[i] = new RecordingDevice(devnames[i].c_str());
|
if (devnames[i] == c->getName())
|
||||||
|
*d = c;
|
||||||
|
|
||||||
|
if (*d == nullptr)
|
||||||
|
*d = new RecordingDevice(devnames[i].c_str());
|
||||||
|
else
|
||||||
|
(*d)->retain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto c : capture)
|
||||||
|
c->release();
|
||||||
capture.clear();
|
capture.clear();
|
||||||
|
capture.reserve(devices.size());
|
||||||
|
|
||||||
|
//this needs to be executed in specific order
|
||||||
for (unsigned int i = 0; i < devnames.size(); i++)
|
for (unsigned int i = 0; i < devnames.size(); i++)
|
||||||
capture.push_back(devices[i]);
|
capture.push_back(devices[i]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user