1

I am assisting some friends on an Arduino Uno project, and we've noticed that when using some earlier versions of the Arduino IDE (In this case 1.0.5), the sketch behaves as desired. However, when using 1.6.5, the program behaves differently. The sketch in question is here:

https://github.com/CymaSpace/Programs---Sketches/tree/master/Tim%20Gorbunov/a3%20with%20monosetting/a3

I have noticed that when enabling verbose compilation output, the size of the compiled binary is different between the two different IDE versions. There are also some warnings in the older IDE that are not present in the newer version. There is at least one other version before 1.6.5 that is behaving the same way as 1.0.5 (it's a later version but at the moment I don't know which, I will see if I can find out and post it here later).

Any idea why the two sketches might be behaving differently and how to go about troubleshooting the problem? This occurred on both a windows and mac computer. Thanks!

5
  • Because they're using different versions of the compiler. Commented Jul 3, 2015 at 7:22
  • @IgnacioVazquez-Abrams Is there a way to rectify the differences or at the very least to figure out what has changed between the two compiled sketches?
    – Hendeca
    Commented Jul 3, 2015 at 7:35
  • You can use avr-objdump to disassemble the compiled binaries. Commented Jul 3, 2015 at 7:42
  • Could you be more specific about how the behaviors differ? Maybe you can pinpoint the specific function that is behaving differently? You could try to disassemble and look for the differences, or upload the ELF files somewhere to get help on this. Commented Jul 3, 2015 at 7:43
  • The sketch is intended to display colors on a strip of WS2812b's based on sound input from two MSGEQ7's. In the older version, the animations stop when there is no more audio input. In the new version, the animations continue even if there is no input coming in. This is somewhat of a simplified explanation. I'm thinking that the code likely needs to be refactored, as there are a few flaws that were pointed out that could be making the sketch behave erratically. After refactoring the code, I will retest it and if it's still having problems, I'll upload the ELF files and disassemble the binaries
    – Hendeca
    Commented Jul 3, 2015 at 8:43

1 Answer 1

0

There are also some warnings in the older IDE that are not present in the newer version.

It is a huge mistake to disregards those warnings, especially:

warning: array subscript is above array bounds

You declared an array int useColor[2]. Its length is 2 and its indices can be either 0 or 1. Yet you are using useColor[2], which is out of bounds and likely to corrupt memory.

From the language point of view, this is called undefined behavior, which means that anything can happen. In particular, it could very well happen that the program behaves as you expect... which seems to be the case with IDE 1.0.5. Simply changing the compiler version, or event the compiler settings, can change the behavior.

4
  • Good point. I think the best thing to do at this point might be to revisit the code, clean it up, resolve any errors, and make sure there isn't any undefined behavior. It might be a waste of time to compare the binaries if the code has inherent problems. I'm going to try to refactor some of it and see if the discrepancy still exists. Thanks for the tips and for catching that array out of bounds problem!
    – Hendeca
    Commented Jul 3, 2015 at 8:36
  • @Hendeca: I tried some minimal cleanup on your code. Check your github repo for the pull request. Commented Jul 3, 2015 at 11:05
  • Thanks very much! Very helpful. We will test this out and keep refactoring from there. Also, this is collaborative and I was unaware that this is an earlier version of the code. I'll edit the question to point to the new version of the code. I will likely just do the same changes you made in your pull request to the newer sketch. If you so desire, feel free to put in another pull request on the new sketch. Sorry about the confusion and thanks again for your help, it's much appreciated!
    – Hendeca
    Commented Jul 3, 2015 at 18:34
  • The original code was contributed to by many different people over a long period of time. I went through and completely refactored and cleaned up the code. It now works and I believe that the array out of bounds problem was likely the culprit. To me it explains most reasonably why it would behave so different between two different compilations on different versions of the Arduino IDE. Accepting this as the correct answer. Thanks!
    – Hendeca
    Commented Jul 21, 2015 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.