Skip to content

Commit e2766d4

Browse files
committed
Merge pull request godotengine#105734 from erodozer/fix-v4l2-camerafeed-id
Fix camera feed device order on Linux
2 parents 04bcd4c + 5dc4ac2 commit e2766d4

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

modules/camera/camera_linux.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ void CameraLinux::_update_devices() {
6161
}
6262
}
6363

64-
DIR *devices = opendir("/dev");
65-
66-
if (devices) {
67-
struct dirent *device;
68-
69-
while ((device = readdir(devices)) != nullptr) {
70-
if (strncmp(device->d_name, "video", 5) != 0) {
71-
continue;
72-
}
73-
String device_name = String("/dev/") + String(device->d_name);
74-
if (!_has_device(device_name)) {
75-
_add_device(device_name);
64+
struct dirent **devices;
65+
int count = scandir("/dev", &devices, nullptr, alphasort);
66+
67+
if (count != -1) {
68+
for (int i = 0; i < count; i++) {
69+
struct dirent *device = devices[i];
70+
if (strncmp(device->d_name, "video", 5) == 0) {
71+
String device_name = String("/dev/") + String(device->d_name);
72+
if (!_has_device(device_name)) {
73+
_add_device(device_name);
74+
}
7675
}
76+
free(device);
7777
}
7878
}
7979

80-
closedir(devices);
80+
free(devices);
8181
}
8282

8383
usleep(1000000);

0 commit comments

Comments
 (0)