I have a C project for Playdate and encountered crashes on the device, but not in the simulator.
I distilled the problem to the following code, which reproduces the crashes:
Attached project
typedef uint32_t MapDimension;
typedef struct
{
MapDimension x;
MapDimension y;
MapDimension z;
}MapPosition;
size_t bufferSize = 100;
size_t offset = 1;
void* buffer = pd->system->realloc(NULL, bufferSize);
memset(buffer, 0, bufferSize);
MapPosition* mp = (char*)buffer + offset;
mp->x = 1;
mp->y = 2;
mp->z = 3;
// if MapDimension is defined as uint32_t
// This will crash device if offset is 1,2,3
// This will not crash device if offset is 0,4,8,12 ...
MapPosition mpCopy = *mp;
// if MapDimension is defined as uint16_t or uint8_t it works as intended.
// In simulator everything always works.
I am working on Windows and using SDK Version 2.5.0.
What am I missing? I saw couple of threads about crashes on device and not in simulator could this be piece of puzzle?
Looking forward to your response.