C++快板: Program Crashes when I move the window

标签 c++ crash allegro

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

这是我的代码的主要部分。

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

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

有人有什么想法吗?

最佳答案

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

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

关于C++快板: Program Crashes when I move the window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8011395/

相关文章:

C++:是否有包含各种函数的特征类来操作零终止的 char * 和 wchar_t * 字符串?

java - Java 开发人员学习 C++ 的最佳方法是什么

iphone - 超过150张图像的ScrollView崩溃

c# - 由于 CLR.dll Windows 应用程序崩溃 - Windows 2008 R2 Server

c - malloc() 函数崩溃

c++ - 使用模板定义 bitset 的大小

c++ - 此示例中指定的 128 位 AES key 是什么格式?

c++ - 在 C++ 中渲染 vector 图形 (.svg)

C/C++ Allegro 程序导致 Windows 7 切换到 Aero Basic

c - 构建具有 Allegro 依赖项的 C 项目