2011-11-04 31 views
0

我已經構建了一個C++ Allegro貼圖編輯器。其中一個要求是有一個日誌,所以我已經把它放在控制檯窗口中進行每一個動作......現在問題是控制檯窗口在主窗口下(使用GFX_AUTODETECT_WINDOWED),但是每當我嘗試移動該窗口,它只會崩潰程序..我需要能夠移動它並將控制檯窗口移動到並返回到地圖編輯器。任何人有任何想法?C++ Allegro:當我移動窗口時程序崩潰

這是我的代碼的主要部分。

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

此外,它確實發生了它本身隨機崩潰而不移動窗口。沒有特定的原因,它只是隨機崩潰。

任何想法的人?

+0

爲什麼在返回0後調用'allegro_exit'? – Marlon

回答

0

沒有看到所有的代碼,它是不可能知道它爲什麼或它崩潰的地方。如果您使用調試器,應該很明顯發生了什麼。您應該回復代碼。例如,當您加載或創建位圖時,確保它不是NULL

我不確定你想用這麼小的雙緩衝區來做什麼。通常,您創建一個與窗口大小相同的單個緩衝區。請注意,如果屏幕寬度是4的倍數,Allegro 4將只能正常工作。此外,您應該調用set_color_depth(desktop_color_depth())(在設置圖形模式之前)以獲得最大的兼容性。