Compiler completely freezes and dies when compiling

05 Mar 2012

Recently when I try to compile my project, the entire compiler would freeze up, crash, and I can no longer access the compiler for about 10 minutes. Has anyone experience this before? How can I fix it?

This is the program that I was trying to compile http://mbed.org/users/kagelump/programs/DisplayTest/m6e9nv

06 Mar 2012

Hi Ryan,

Having had a look at this issue, it seems there are few things here to consider.

The first is that the fonts you are using are memory hungry. I added up the array sizes and by the time I got to Comic24.h, there were 64k bytes of arrays. The problem with this is that the arrays are being declared as variables, and so they will be placed in RAM. As the LPC1768 only has 32kB of RAM, this isn't going to work.

The solution to this is to define the arrays as "const" so that they are allocated into the FLASH which we have 512kB of!

The next thing is more of a coding style suggestion. Rather than defining the font arrays in the .h header files, the definitions should be in .cpp code files. Even though you have the #ifndef keywords in your headers that only prevents the same header being included twice in the same .cpp file (also known as a compilation unit). In the scheme you have,there is nothing stopping the .h file being included in multiple .cpp files, which will lead to multiple copies of the data in your final image.

A natural way to implement this is to make the font definition in a .cpp file, and then have an associated header file make a declaration of the array so it can be made visible in multiple .cpp file. This way the definition can only ever be compiled once, and therefore one copy appear in the image.

There are some great notes on the compilation process in the Course Notes that have been published, which work well as a tutorial or just a reminder :

I have published a example showing how this might work in your scenario :

Comic24.cpp

    // This is where the array is defined, 
    // as an externally visible constant array.

    extern const unsigned char Comic24[] = {
    ... , // data
    ... ,
    ... ,
    }

Comic24.h

// Make the array visible externally
extern const unsigned char Comic24[];

main.cpp

#include "mbed.h"
#include "Comic24.h"

int main() {

    printf("\nPrinting first 10 bytes of Comic24\n");

    for (int i=0; i<10 ; i++) {
        printf("%x, ",Comic24[i]);
    }

    printf("\n\nDone!\n");
}

The last point is more a reminder for us that we need to ensure that the IDE deals more gracefully with processes that do not terminate. We have a ticket open on this now, and it will resolved in a future release.

Hope this helps!

Regards, Chris

04 Apr 2012

Hi, Thanks for the reply, I didn't realize there was binary data in one of the files. The problem seems to have went away (although my mouse curser is now perpetually in the "loading" state).

I'll implement your suggestions.