0

I have the following function:

static void ClearDisplay(void)
{
  int X,Y;
  GuiConst_INT16U *PixelPtr;
  GuiConst_INT16U PIXEL_OFF = 65535; 

  PixelPtr = (GuiConst_INT16U*)sgl.CurLayerBufPtr;
  for (Y = 0; Y < (GuiConst_INT16S)sgl.CurLayerHeight; Y++)
    for (X = 0; X < (GuiConst_INT16S)sgl.CurLayerWidth; X++)
    {
      *PixelPtr = PIXEL_OFF;
      PixelPtr++;
    }
}

The following line causes a SIGTRAP interrupt when debugging, throwing a Guru Meditation Error with code LoadStoreError:

*PixelPtr = PIXEL_OFF;

After searching this up, I found the following:

This exception may happen in the following cases:

  • If the application has attempted to do an 8- or 16- bit read to, or write from, a memory region which only supports 32-bit reads/writes. For example, dereferencing a char* pointer to instruction memory (IRAM, IROM) will result in such an error.

  • If the application has attempted to write to a read-only memory region, such as IROM or DROM.

So I'm assuming the problem relates to the former since neither PixelPtr nor PIXEL_OFF are assigned const. I thought the problem would be cleared up if I set them both to the same datatype, GuiConst_INT16U (which is an unsigned short in the code), but the problem persists. What am I missing here?

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Jebussy
  • 11
  • 4
  • What address does `PixelPtr` point to? – Codo Jan 26 '22 at 19:05
  • You're using a variable called `sgl` but we have no idea what it is or where it came from. Please provide all the relevant code. – romkey Jan 26 '22 at 19:13
  • Does this answer your question? [Crash or "segmentation fault" when data is copied/scanned/read to an uninitialized pointer](https://stackoverflow.com/questions/37549594/crash-or-segmentation-fault-when-data-is-copied-scanned-read-to-an-uninitializ) – the busybee Jan 27 '22 at 08:11

0 Answers0