Skip to content

Commit 5198054

Browse files
committed
Examples: throw an exception when no stream could be resolved instead of passing results[0] to the stream_inlet constructor
1 parent e16db05 commit 5198054

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

examples/ReceiveData.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int main(int argc, char* argv[]) {
3939
// resolve the stream of interet
4040
std::cout << "Now resolving streams..." << std::endl;
4141
std::vector<lsl::stream_info> results = lsl::resolve_stream(field, value);
42+
if(results.empty()) throw std::runtime_error("No stream found");
4243

4344
std::cout << "Here is what was resolved: " << std::endl;
4445
std::cout << results[0].as_xml() << std::endl;

examples/ReceiveDataC.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char* argv[]) {
1616

1717
/* resolve the stream of interest (result array: info, array capacity: 1 element, type shall be EEG, resolve at least 1 stream, wait forever if necessary) */
1818
printf("Now waiting for an EEG stream...\n");
19-
lsl_resolve_byprop(&info,1, "type","EEG", 1, LSL_FOREVER);
19+
lsl_resolve_byprop(&info, 1, "type","EEG", 1, LSL_FOREVER);
2020

2121
/* make an inlet to read data from the stream (buffer max. 300 seconds of data, no preference regarding chunking, automatic recovery enabled) */
2222
inlet = lsl_create_inlet(info, 300, LSL_NO_PREFERENCE, 1);

examples/ReceiveDataInChunks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(int, char* []) {
1313
try {
1414

1515
// resolve the stream of interest & make an inlet
16-
lsl::stream_inlet inlet(lsl::resolve_stream("name", "MyAudioStream")[0]);
16+
lsl::stream_inlet inlet(lsl::resolve_stream("name", "MyAudioStream").at(0));
1717

1818
// and retrieve the chunks (note: this can of course also be done with pure std::vectors
1919
// instead of stereo_samples)

examples/ReceiveDataSimple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int main(int argc, char** argv) {
1111

1212
// resolve the stream of interest & make an inlet to get data from the first result
1313
std::vector<stream_info> results = resolve_stream("name", argc > 1 ? argv[1] : "SimpleStream");
14-
stream_inlet inlet(results[0]);
14+
stream_inlet inlet(results.at(0));
1515

1616
// receive data & time stamps forever (not displaying them here)
1717
std::vector<float> sample;

0 commit comments

Comments
 (0)