-
Notifications
You must be signed in to change notification settings - Fork 32
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
C++ Example - ParallelProbe Errors (Apple clang) #33
Comments
I think I was able to solve the above issues. However, I am relatively new to C++ and not well-versed in its lambda syntax/std::async/etc. If anyone could quickly glance over this, that would be much appreciated!
I'm not sure if this last fix is correct. While it makes the code compile, I could definitely be missing something. I'll test this code when I next have access to an NDI camera, and I'll update this thread with the results. In the meantime, it would be great to have someone else check over the above code if possible. Thank you! |
While not technically a compilation error, I also had to change // Old code
std::string devName;
{
std::lock_guard<std::mutex> guard(deviceNameMutex);
devName = std::string(ndiSerialDeviceName(i));
}
int errnum = ndiSerialProbe(devName.c_str(),checkDSR);
if (errnum == NDI_OKAY)
{
deviceExists[i] = true;
}
// New code (+ minor optimization)
std::string devName;
{
std::lock_guard<std::mutex> guard(deviceNameMutex);
const char* name = ndiSerialDeviceName(i);
if (name == nullptr)
{
return;
}
devName.assign(name); // use .assign() instead of constructing another std::string object
}
int errnum = ndiSerialProbe(devName.c_str(), checkDSR);
if (errnum == NDI_OKAY)
{
deviceExists[i] = true;
} I think the segfaults occurred when Now |
I made a new version of ndicapi* ParallelProbe(bool checkDSR, int maxPortNum)
{
std::vector<std::future<std::string>> probeTasks;
for (int i = 0; i < maxPortNum; i++)
{
// get serial port #i's full name (e.g., "COM*" on Windows, "/dev/cu.usbserial-******" on macOS)
const char* portName = ndiSerialDeviceName(i);
if (portName == nullptr) // port #i doesn't exist
{
continue;
}
// check if device at port #i is an NDI camera; return its full name if so, otherwise return an empty string
probeTasks.push_back(std::move(std::async(std::launch::async, [portName, checkDSR]()
{
std::string portNameStr(portName); // copy portName to this task's thread
return ndiSerialProbe(portNameStr.c_str(), checkDSR) == NDI_OKAY ? portNameStr : std::string();
}
)));
}
// wait for each task to finish; return first (i.e. lowest port # due to above loop) NDI device found
for (auto& probeTask : probeTasks)
{
std::string portName = probeTask.get();
if (!portName.empty())
{
return ndiOpenSerial(portName.c_str());
}
}
return nullptr;
} I have tested it on macOS, and it works well. I will try to test on Windows next. |
Hello! When compiling
/Applications/ndiBasicExample.cxx
(renamed to.cpp
), I encounter the following compilation errors (Apple clang version 14.0.0, x86-64, macOS 12.5):While I see that
ParallelProbe
is technically only supposed to be compiled (i.e., supported) on MSVC 1700 (v11.0) or higher, wanted to try to adapt and compile it for my Mac.The text was updated successfully, but these errors were encountered: