0

I Have built a C++ Allegro Map Editor. One of the requests was to have a log so I've put it in the console window for every move that is made... Problem now is that the console window is under the main window (Used GFX_AUTODETECT_WINDOWED), But whenever I try to move that window, it simply crashes the program.. I need to be able to move it and to move the console window to and come back to the map editor. Anybody has any ideas???

Here's the main of my code.

#include <allegro.h>
#include <string>
#include <sstream>
#include "Layout.h"
#include "System.h"
#include "Map.h"
#include <iostream>
#include <fstream>

using namespace std;

// Allegro Functions to stabilize speed
volatile long speed_counter = 0;              
void increment_speed_counter() // A function to increment the speed counter
{speed_counter++; }
END_OF_FUNCTION(increment_speed_counter); 

int main()
{
System system; // Initialising Allegro 
system.Setup();

Map map1; // Creating default map
map1.createMap(); 

BITMAP *buffer = create_bitmap(24,45); // Double buffering

LOCK_VARIABLE(speed_counter); //Used to set the timer - which regulates the game's
LOCK_FUNCTION(increment_speed_counter);//speed.
install_int_ex(increment_speed_counter, BPS_TO_TIMER(8));//Set our BP

/*game looop */
while( !key[KEY_ESC] )
{
        clear_bitmap(buffer); // Clear the contents of the buffer bitmap         
while(speed_counter > 0)
{
    if(mouse_b &1 ){ // On mouse click
          map1.catchMouseEvent(mouse_x, mouse_y);
          while(mouse_b & 1){}   
    }
    speed_counter --;
}
       rectfill(buffer,0,0,25,45,makecol(135,206,250));
       textprintf_ex(buffer, map1.getLayout().getFont(), 0, 0, makecol(255, 255, 255), -1,"%d", map1.getRowVal());
       textprintf_ex(buffer, map1.getLayout().getFont(), 0, 20, makecol(255, 255, 255), -1,"%d", map1.getColVal());

       blit(buffer, screen, 0, 0, 970, 50, 100, 50);     
}

/*Free memory after */
destroy_bitmap( buffer );   
return 0;
allegro_exit();
}
END_OF_MAIN();

Also, it does happen that it randomly crashes by itself without moving the window. There is not a specific reason, it just crashes at random times.

Any ideas someone?

user925890
  • 11
  • 2

1 Answers1

0

Without seeing all of the code, it's impossible to know why or where it's crashing. If you use a debugger it should be obvious what's happening. You should be responding to return codes. e.g., When you load or create a bitmap, make sure it's not NULL.

I'm not really sure what you are trying to do with such a smaller double buffer. Typically you create a single buffer the same size as the window. Note that Allegro 4 will only work properly if the screen width is a multiple of four. Also, you should call set_color_depth(desktop_color_depth()) (before setting the graphics mode) for maximum compatibility.

Matthew
  • 47,584
  • 11
  • 86
  • 98