Oops! Error 2 :( Hard fault


2 months ago

Hi, got this nice error message with a bin that works in the online emulator and I don't know what to investigate.

I have removed late portions of my code and it still doesn't work, any idea how to debug? I don't know what these mean...

Thanks in advance for any help!


NEW 2 months ago

Hi YQN to have a good idea and gain time, it's will be great to have a link to the source code to check it and see whee could be the problem


NEW 2 months ago

Common problems are for a hard fault are things like....

Array Overflow

Let's say you made an array of length n, and now you try to access past the array, e.g.:

int myArray[16];
int somevar = myArray[16]; // COULD lead down the road to a hard fault

for (int i = 0; i <= 16; i++) { // as i can also be 16 here, it also COULD lead to a hard fault
    int val = myArray[i];

RAM overflow

This is if you use too much RAM than you have. This is rather tricky to debug, just try to output gb.getFreeRam() here and there to see where you are hitting a lot of RAM

Undefined instructions and unaligned addresses isn't something to worry about. In fact, the array overflow often leads to either of those two, causing the hard fault.


NEW 2 months ago

JCL, thanks, I just hoped it would be ok without the code because I can't access my github right now and the code is big for a single forum message, with many files (trying to learn MVC architecture).

It was an array issue as Sorunome suggested. I declared an array of size 48 and set values up to 28 only, then browsed the array up to 48, didn't think such an error would pass the emulator test!

Thanks guys! I'm back on track! :D


NEW 2 months ago

Yeah, once you read past an array you land in undefined behaviour, so who knows what'll happen!

You must be logged in in order to post a message on the forum

Log in