0

我已经构建了一个 C++ Allegro 地图编辑器。其中一个请求是要有一个日志,所以我已经将它放在控制台窗口中以进行每一次移动......现在的问题是控制台窗口位于主窗口下方(使用 GFX_AUTODETECT_WINDOWED),但每当我尝试移动那个窗口,它只会使程序崩溃。我需要能够移动它并将控制台窗口移动到并返回到地图编辑器。有人有什么想法吗???

这是我的主要代码。

#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();

此外,它确实会在不移动窗口的情况下自行随机崩溃。没有具体原因,它只是随机崩溃。

有人有什么想法吗?

4

1 回答 1

0

如果不查看所有代码,就不可能知道崩溃的原因或位置。如果您使用调试器,那么发生的事情应该很明显。您应该响应返回代码。例如,当您加载或创建位图时,请确保它不是NULL.

我不太确定你想用这么小的双缓冲区做什么。通常,您创建一个与窗口大小相同的缓冲区。请注意,Allegro 4 仅在屏幕宽度为四的倍数时才能正常工作。此外,您应该调用set_color_depth(desktop_color_depth())(在设置图形模式之前)以获得最大的兼容性。

于 2011-11-05T18:43:57.250 回答