From c735ee6de7928e1e47ef5c18980c66216bc85460 Mon Sep 17 00:00:00 2001 From: Suisse00 Date: Sat, 20 Jul 2019 14:50:12 -0400 Subject: [PATCH] Fixing NullReferenceException because of readStringUntil 1) readStringUntil isn't a blocking method 2) 64 is like 1/6 of the size of the packet we are waiting, so we could end up calling readStringUntil way too early. --- examples/Example4-ProcessingHeatCam/HeatCam/HeatCam.pde | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/Example4-ProcessingHeatCam/HeatCam/HeatCam.pde b/examples/Example4-ProcessingHeatCam/HeatCam/HeatCam.pde index 76b8287..6fba64d 100644 --- a/examples/Example4-ProcessingHeatCam/HeatCam/HeatCam.pde +++ b/examples/Example4-ProcessingHeatCam/HeatCam/HeatCam.pde @@ -72,6 +72,11 @@ void draw() { if(myPort.available() > 64){ myString = myPort.readStringUntil(13); + // readStringUntil is a non-blocking function and will return null if it can't find the linefeed + if(myString == null){ + return; + } + // generate an array of strings that contains each of the comma // separated values String splitString[] = splitTokens(myString, ","); @@ -117,4 +122,4 @@ void draw() { // Add a gaussian blur to the canvas in order to create a rough // visual interpolation between pixels. filter(BLUR,10); -} \ No newline at end of file +}