Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm having a serious problem with allegro. The program should display random pixels on the screen and when I build and run it I get the following error message:

Below is the full code of my program:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "allegro.h"

#define Text_Color_Red makecol(255,0,0)
int main()
{
    int ret;
    int color_depth = 32;
    int x;
    int y;
    int red;
    int green;
    int blue;
    int color;

    //init allegro
    allegro_init();

    //install keyboard
    install_keyboard();

    //set color depth to 32 bits
    set_color_depth(color_depth);

    //init random seed
    srand(time(NULL));

    //init video mode to 640 x 480
    ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);

    if(ret !=0)
    {
        allegro_message(allegro_error);
        return 1;
    }

    //Display string
    textprintf(screen,font,0,0,10,0,Text_Color_Red,"Screen Resolution is: %dx%d -- Press ESC to quit !",SCREEN_W,SCREEN_H);

    //display pixels until ESC key is pressed
   //wait for keypress
    while(!key[KEY_ESC])
    {
        //set a random location
        x = 10 + rand() % (SCREEN_W-20);
        y = 10 + rand() % (SCREEN_H-20);
        //set a random color
        red = rand() % 255;
        green = rand() % 255;
        blue = rand() % 255;
        color = makecol(red,green,blue);
        //draw the pixel
        putpixel(screen, x, y, color);
    }

    //quit allegro
    allegro_exit();
}

END_OF_MAIN()

Error message: AllegroPixels1.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

Error signature: AppName: allegropixels1.exe AppVer: 0.0.0.0 ModName: alleg42.dll ModVer: 4.2.3.0 Offset: 0006c05c

I am using Windows XP inside a virtual machine under Parallels 7.0

share|improve this question
    
Is the dll that you're using compatible with your compiler? Not all dll's are created alike. You might also try to comment out everything between allegro_init() and allegro_exit(). See if your program still crashes. If it does not then you know the problem is part of the commented out code. Then add code back in one piece at a time to determine where the problem is. –  Jay Dec 19 '12 at 20:13

3 Answers 3

Running the debugger pointed to the textprintf line being the culprit. You have an extra parameter 10 in there that should not be there. Fixing that solved the problem.

HOWEVER, there are other problems with the code:

  1. You are using the old version of textprintf use the new version like so:

    textprintf_ex(screen, font, 0, 0, Text_Color_Red, -1, "Screen Resolution is: %dx%d -- Press ESC to quit !", SCREEN_W, SCREEN_H);

  2. You are not calling acquire_screen() before you draw to the screen and release_screen() after you are done drawing.

  3. Most importantly, you are not having main return 0 at the end of the function.

share|improve this answer

You should debug your program line by line to find the exact line the crash happens. It's been a while since I've used Allegro, but from what I see this should work.

share|improve this answer

First off, Allegro 4.2 is painfully old. Allegro 4.4 is source compatible. Allegro 5 is recommended, but has a totally different API.

The likely culprits:

  1. The DLL you are using is not compatible with your compiler. You cannot mix and match. You cannot use a 4.2.0 DLL with a 4.2.2 program. You cannot use a gcc-built assembly enabled DLL with a C-only MSVC build, etc.

  2. Running inside a VM is not going to be very pleasant. In the very least, you should probably use GFX_GDI as the graphics driver and set_color_depth(desktop_color_depth()).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.