Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leaked Path class #12

Open
bparks13 opened this issue Feb 4, 2025 · 1 comment
Open

Fix leaked Path class #12

bparks13 opened this issue Feb 4, 2025 · 1 comment
Assignees

Comments

@bparks13
Copy link
Member

bparks13 commented Feb 4, 2025

Somewhere in creating the OnixSourceCanvas, specifically the device interfaces for Neuropixels 1.0f (i.e., Bno055Interface and NeuropixV1Interface), there is a leaked Path. Initial testing also indicated that there are device classes leaked from these interfaces. Figure out where the issue is coming from, and plug the leak.

See #11 for a related issue.

@bparks13 bparks13 self-assigned this Feb 4, 2025
@bparks13 bparks13 added this to the Neuropixels 1.0f milestone Feb 4, 2025
@bparks13
Copy link
Member Author

bparks13 commented Feb 4, 2025

In #17, adding the related macros shows that the devices instantiated are actually what is leaking, but I can't figure out exactly where they are leaking. There are no additional classes that are registered as being leaked, indicating it is something with the device pointers themselves. Specifically, the following lines can be removed to fix the leak, but then nothing downstream happens:

if (devices[dev_idx].id == ONIX_NEUROPIX1R0)
{
auto np1 = std::make_unique<Neuropixels_1>("Probe-" + String::charToString(probeLetters[npxProbeIdx]), this, devices[dev_idx].idx, ctx);
int res = np1->enableDevice();
if (res != 0)
{
if (res == -1)
{
LOGE("Device Idx: ", devices[dev_idx].idx, " Unable to read probe serial number. Device not found.");
continue;
}
else if (res == -2)
{
LOGE("Device Idx: ", devices[dev_idx].idx, " Error enabling device stream.");
continue;
}
else if (res == -3 || res == -4)
{
LOGE("Missing or invalid calibration file(s). Ensure that all calibration files exist and the file paths are correct.");
}
}
sources.add(np1.release());
npxProbeIdx++;
}
else if (devices[dev_idx].id == ONIX_BNO055)
{
auto bno = std::make_unique<Bno055>("BNO-" + String::charToString(probeLetters[bnoIdx]), devices[dev_idx].idx, ctx);
int result = bno->enableDevice();
if (result != 0)
{
LOGE("Device Idx: ", devices[dev_idx].idx, " Error enabling device stream.");
continue;
}
sources.add(bno.release());
bnoIdx++;
}
else if (devices[dev_idx].id == ONIX_DS90UB9RAW)
{
LOGD("Passthrough device detected");
//initialize main i2c parameter
auto serializer = std::make_unique<I2CRegisterContext>(DS90UB9x::SER_ADDR, devices[dev_idx].idx, ctx);
serializer->WriteByte((uint32_t)DS90UB9x::DS90UB9xSerializerI2CRegister::SCLHIGH, 20);
serializer->WriteByte((uint32_t)DS90UB9x::DS90UB9xSerializerI2CRegister::SCLLOW, 20);
auto EEPROM = std::make_unique<HeadStageEEPROM>(devices[dev_idx].idx, ctx);
uint32_t hsid = EEPROM->GetHeadStageID();
LOGD("Detected headstage ", hsid);
if (hsid == 8) //Npix2.0e headstage, constant needs to be added to onix.h
{
auto np2 = std::make_unique<Neuropixels2e>("Probe-" + String::charToString(probeLetters[npxProbeIdx]), devices[dev_idx].idx, ctx);
int res = np2->enableDevice();
if (res != 0)
{
if (res == -1)
{
LOGE("Device Idx: ", devices[dev_idx].idx, " Unable to read probe serial number. Device not found.");
}
//TODO add other errors if needed
continue;
}
npxProbeIdx += np2->getNumProbes();
sources.add(np2.release());
}
}

If these lines are left in, I have tried to selectively remove lines from other classes to find the leak, such as removing the lines that create the interfaces in OnixSourceCanvas, but none of these modifications fix it.

Prior to f8d65b2, I don't remember this being an issue. However, cherry-picking changes from this commit do not seem to fix the issue, so maybe it started occurring prior to this and I did not notice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant