Arduboy2Base::fillRect is giving me trouble [Solved]

#include <Arduboy2.h>


Arduboy2Base arduboy;

void setup() {
  arduboy.boot();
  arduboy.audio.begin();
  //arduboy.setFrameRate(FPS);

  //Start serial
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Entering setup");
  
  Serial.println("Exiting setup");
}

void loop() {
  Serial.println("Entering loop");
  // put your main code here, to run repeatedly:
  arduboy.clear();
  arduboy.fillRect(0, 0, WIDTH-1, HEIGHT-1);
  arduboy.display();
  Serial.println("Exiting setup");
}

My problem is fillrect is hanging.

with this output on serial:

Entering setup
Exiting setup
Entering loop

If I switch the arduboy class declaration to be Arduboy2 it works. Also if I roll back the Arduboy2 library to 3.1.1 it works. I’m currently trying to use 4.0.0.

I’m confused because the Arduboy2 library hasn’t been updated Since Apr 26 and I wasn’t having any trouble before this evening.

Am I missing something? I feel like I’m loosing my mind. :sweat_smile:

Are WIDTH and HEIGHT defined somewhere?

What happens if you use Arduboy::width() and Arduboy2::height() instead of WIDTH and HEIGHT?

Also I’m pretty sure there’s no such thing as Arduboy2Base,
There’s an Arduboy2Core, but that doesn’t have fillRect.

I’m presuming those are the WIDTH and HEIGHT defined in <Arduboy2.h>.

#define WIDTH 128 /**< The width of the display in pixels */
#define HEIGHT 64 /**< The height of the display in pixels */

Arduboy2Base is used by Virus-LQP in globals.cpp

@Pharap https://mlxxxp.github.io/documents/Arduino/libraries/Arduboy2/Doxygen/html/classArduboy2Base.html

I’m pretty sure you didn’t read the Arudyboy2 library documentation.

On the Main Page, see the section titled Ways to make more code space available to sketches, subsection Remove the text functions.

1 Like

I double checked, there is an Arduboy2Base, it’s in the same file as Arduboy2 for some reason. Didn’t realise Arduboy2 has a 3-stage inheritance chain.

fillRect is definitely on Arduboy2Base so disregard my earlier statement.

I’ve narrowed the problem down.
It seems that it’s fine creating rectangles up to 8x8, but any larger than that and it locks up for some reason.

The biggest difference between the versions (3.1.1 and 4.0.0) is that 4.0.0 is now using some assembly, so it could be something to do with register clobbers. Seems odd that Arduboy2 doesn’t have the problem but Arduboy2Base does.

@SerendipityDoDa,

Sorry about that. It’s a problem with the library drawPixel() function. :sob:

For the v4.0.0 release, @Dreamer3 provided a modified version of drawPixel() which uses some assembler to reduce code size and improve speed. There’s a problem with this new code which causes it to sometimes hang.

Until the problem is sorted out, you could revert back to Arduboy2 library v3.1.1 using the Library Manager

Sketch > Include Library > Manage Libraries...
Enter arduboy2 in the Filter your search… field.
Click somewhere in the Arduboy2 entry.
Choose Version 3.1.1 in the Select version pull-down.
Click on Install

If your sketch uses something unique to v4.0.0, preventing you from using v3.1.1, you can replace the Arduboy2Base::drawPixel() function in file Arduboy2.cpp with the previous version:

void Arduboy2Base::drawPixel(int16_t x, int16_t y, uint8_t color)
{
  #ifdef PIXEL_SAFE_MODE
  if (x < 0 || x > (WIDTH-1) || y < 0 || y > (HEIGHT-1))
  {
    return;
  }
  #endif

  uint8_t row = (uint8_t)y / 8;
  if (color)
  {
    sBuffer[(row*WIDTH) + (uint8_t)x] |=   _BV((uint8_t)y % 8);
  }
  else
  {
    sBuffer[(row*WIDTH) + (uint8_t)x] &= ~ _BV((uint8_t)y % 8);
  }
}

Let me know if you need more help with this.

1 Like

I think I’ve isolated the problem to "andi %[y], 0x07\n".
I think writing to y is what’s causing the blocking, but I don’t know why yet.

I seem to have fixed the problem so I’ve submitted a PR.
I’ve only run a limited number of tests but it seems to be working correctly.

1 Like

Excellent, I have temporarily rolled back. I was mostly confused because it went from working to not rather suddenly. Like 4.0.0 just got added to the Arduino library repo.

For those that were wondering. I am using Arduboy2Base because I am using TinyFont. So I didn’t want the default charset included.

1 Like

I only spotted it because I spent ages looking at the code before I increased the zombie spawn rate otherwise I would have probably sailed through never knowing it existed :wink:

2 Likes

Version 4.0.1 of the Arduboy2 library has been released, which includes a fix for this problem.

@SerendipityDoDa, Thanks for reporting this.
@Pharap, Thanks for your help with the fix.

4 Likes