Closed piscodev closed 5 months ago
Thank you for reporting the issue... I will research the issue and get back to you. For now though I will be transferring your issue to the main repository for easier issue tracking. Thank you!
Just for research purposes, how are you iterating over the list? Are you using a for loop with List.get(I) or List.getAsString(i)… OR are you creating an iterator object and using that to iterate over the list?
Just for research purposes, how are you iterating over the list? Are you using a for loop with List.get(I) or List.getAsString(i)… OR are you creating an iterator object and using that to iterate over the list? If you have an sd card reader with the arduino you could also try using the SDList library instead. It used ArrayList in the background but has the ability to save everything to a file and load it back in which may assist in keeping everything valid... I can't guarantee it will work since it does use the ArrayList library in the background and it's not as performant since it saves and loads from a file but this might be a work around. In the mean time I will research the issue as soon as I am able.
Sounds like it could be an issue with the resize function. With 8 tags in the list that is the perfect amount of items to resize. What arduino are you using to run the ArrayList?
Ok sounds good. I'll take a look as soon as I am able.
This issue has been confirmed and patched. The issue was indeed with the way the resize function was copying the data. It was using memcpy. The patch will introduce a new resize2() function and a new DYNAMIC2 option. By default, DYNAMIC2 will now be the default resize function used unless specified. The options will be { FIXED, DYNAMIC, DYNAMIC2 }. The new resize function is a bit goofy in that it will use a forloop and loop through each item in the old array and add it to the new. The original resize function made use of memcpy function instead which seems to be a bit unpredictable with strings.
Here is the test code i used. (I am using the patched Version of ArrayList that will be under the Development Branch. It will be published shortly to Platformio and Arduino Library Manager.
#include <Arduino.h>
#include <ArrayList.h>
ArrayList<String> list;
unsigned long lastMillis = 0;
void setup(){
Serial.begin(9600);
while(!Serial);
delay(5000);
list.add("1234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 0: " + list.get(0));
delay(1000);
list.add("2234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 1: " + list.get(1));
delay(1000);
list.add("3234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 2: " + list.get(2));
delay(1000);
list.add("4234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 3: " + list.get(3));
delay(1000);
list.add("5234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 4: " + list.get(4));
delay(1000);
list.add("6234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 5: " + list.get(5));
delay(1000);
list.add("7234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 6: " + list.get(6));
delay(1000);
list.add("8234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 7: " + list.get(7));
delay(1000);
list.add("9234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 8: " + list.get(8));
delay(1000);
list.add("A234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 9: " + list.get(9));
delay(1000);
list.add("B234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 10: " + list.get(10));
delay(1000);
list.add("C234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 11: " + list.get(11));
delay(1000);
list.add("D234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 12: " + list.get(12));
delay(1000);
list.add("E234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 13: " + list.get(13));
delay(1000);
list.add("F234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 14: " + list.get(14));
delay(1000);
list.add("G234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 15: " + list.get(15));
delay(1000);
list.add("H234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 16: " + list.get(16));
delay(1000);
list.add("I234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 17: " + list.get(17));
delay(1000);
list.add("J234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 18: " + list.get(18));
delay(1000);
list.add("K234567890ABCDEF12345678");
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
Serial.println("Element at index 19: " + list.get(19));
delay(1000);
Serial.println("Removing Now Printing");
for(int i = 0; i < list.size(); i++){
Serial.println(list.get(i));
}
Serial.println("Size: " + String(list.size()));
Serial.println("Capacity: " + String(list.capacity()));
}
void loop(){
}
I have RFID tag scanner, 8 tags on hand, and I store the Strings that are scanned to the <Dynamic list then iterate the list to print out what's inside, however,
After sometime, I just noticed unrecognized strings inside the list, I dont know if its the dynamic size thats causing the bug, or the scanner. Actually, the scanner outputs the string as HEX, and I just converted it to string and it printed fine on Serial Monitor, but not when stored on list.
Here's the logs of the scanned tags:
From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000402B39F5B0E8 [#4] Size: 7 From List: E28068940000502B39F5ACE8 [#5] Size: 7 From List: E28068940000402B39F5A4E8 [#6] Size: 7 From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000402B39F5B0E8 [#4] Size: 7 From List: E28068940000502B39F5ACE8 [#5] Size: 7 From List: E28068940000402B39F5A4E8 [#6] Size: 7 From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000402B39F5B0E8 [#4] Size: 7 From List: E28068940000502B39F5ACE8 [#5] Size: 7 From List: E28068940000402B39F5A4E8 [#6] Size: 7 From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000402B39F5B0E8 [#4] Size: 7 From List: E28068940000502B39F5ACE8 [#5] Size: 7 From List: E28068940000402B39F5A4E8 [#6] Size: 7 From List: E28068940000402B39F5C4E8 [#0] Size: 7 From List: E28068940000502B39F5B8E8 [#1] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 7 From List: E28068940000502B39F5B4E8 [#3] Size: 7 From List: E28068940000502B39F59CE8 [#2] Size: 8 From List: � 68940000502B39F5B4E8 [#3] Size: 8 From List: From List: � 689400005 [#4] Size: 8 From List: � 6894$����� 6894 [#5] Size: 8 From List: E28068940000502B39F5A0E8 [#6] Size: 8 From List: E28068940000502B39F5A0E8 [#7] Size: 8 From List: E28068940000402B39F5C4E8 [#0] Size: 9 From List: E280<From List: E2806 [#1] Size: 9 From List: E28068940000502B39F59CE8 [#2] Size: 9 From List: � 68940000502B39F5B4E8 [#3] Size: 9 From List: From List: E2806$���� [#4] Size: 9 From List: t: ($����E2806894 [#5] Size: 9 From List: E28068940000502B39F5A0E8 [#6] Size: 9 From List: E28068940000502B39F5A0E8 [#7] Size: 9 From List: E28068940000402B39F5A4E8 [#8] Size: 9 From List: Size: \� From Lis [#0] Size: 10 From List: E280<From List: E2806 [#1] Size: 10 From List: E28068940000502B39F59CE8 [#2] Size: 10 From List: � 68940000502B39F5B4E8 [#3] Size: 10 From List: From List: E2806$���� [#4] Size: 10 From List: t: ($����E2806894 [#5] Size: 10 From List: E28068940000502B39F5A0E8 [#6] Size: 10 From List: E28068940000502B39F5A0E8 [#7] Size: 10 From List: E28068940000402B39F5A4E8 [#8] Size: 10 From List: E28068940000502B39F5ACE8 [#9] Size: 10 From List: CE8 [#9] Size: 10omP [#0] Size: 10 From List: E280<From List: E2806 [#1] Size: 10 From List: E28068940000502B39F59CE8 [#2] Size: 10 From List: � 68940000502B39F5B4E8 [#3] Size: 10 From List: From List: E2806$���� [#4] Size: 10 From List: t: ($����E2806894 [#5] Size: 10 From List: E28068940000502B39F5A0E8 [#6] Size: 10 From List: E28068940000502B39F5A0E8 [#7] Size: 10 From List: E28068940000402B39F5A4E8 [#8] Size: 10 From List: E28068940000502B39F5ACE8 [#9] Size: 10