You're getting errors due to changing the Chunk.Data in your keyboard handling code. The your keyboard handler is running in another context/thread (read the doc carefully: http://allegro-pas.sourceforge.net/d...install_int_ex). What does this mean? The data modified in the handler can change at any moment, independently of your main loop routine - if it changes when you're in your Draw routine, all hell's gonna break loose due to invalid pointers etc.
The solution is to just set a flag to signal that a world refresh is needed, and check it in the main loop (and there should be a lock around the flag, to do things 100% properly; but you can probably get away without it in this case).
Code:
var
update_chunks: boolean;
procedure RegenerateChunk;
begin
update_chunks := false;
Chunk.Data:=WorldGenerator.GenerateChunkData(chunkx,0,18);
Inc(chunkx);
al_clear_to_color(perlin,al_makecol(255,0,255));
for x:=0 to 100-1 do
begin
for y:=0 to 100-1 do
begin
al_putpixel(perlin,x,y,generate_pixel(x,y));
end;
end;
end;
procedure update_keyboard();
begin
Dec(lasted);
dec(chunklasted);
if (al_keyboard_needs_poll) then al_poll_keyboard;
if ((al_key[AL_KEY_P]<>0) and (lasted<=0)) then begin pause:=not pause; lasted:=pausedelay; end;
if not pause then begin
if ((al_key[AL_KEY_SPACE]<>0) and (chunklasted<=0)) then
begin
update_chunks := true;
chunklasted:=pausedelay;
end;
end;
end;
main routine:
Code:
repeat
draw;
if update_chunks then
RegenerateChunk;
until (al_key[AL_KEY_Q]<>0) or quit;
Bookmarks