ceu-lang / ceu

The Programming Language Céu

Home Page:http://www.ceu-lang.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use "kill" command makes application terminates unexpectedly

AnnyCaroline opened this issue · comments

Example of application that produces an error (it is using pico-ceu, but it also seems to happen with ceu-sdl and ceu):

emit FRAMES_SET(yes);

code/call Random_Int(var int lower, var int upper) -> int do
    escape (_rand() % (upper - lower + 1)) + lower; 
end

code/await Pixel (none) -> (event none die) -> none do
    var int x = call Random_Int(-25, 25);
    var int y = call Random_Int(-25, 25);
    
    par/or do
        every FRAMES_REDRAW do
            emit GRAPHICS_SET_COLOR_NAME(COLOR_RED);
            emit GRAPHICS_DRAW_PIXEL(x,y);
        end
    with
        await die;
    end
end

pool[5] Pixel pixels;

par do
    every 1ms do
        spawn Pixel() in pixels;
    end
with
    var int i=0;
    every 2ms do
        var&? Pixel pixel;
        loop pixel in pixels do
            _printf("%d\n",i);
            kill pixel;
            //emit pixel!.die;
            i=i+1;
        end
    end
end

The above code produces the following output. The number of times that the loop iterates before produces an error seem to be random.

cd "c:\Users\Anny\Desktop\ceu-curso\exemplos_e_exercicios\slide10\/dist/" && "./tmp.exe"
0
1
2
3
4
5
make: *** [Makefile:26: all] Error -1073741819

Finalizing the code/await Pixel using an internal event (commented on the code above) instead of using kill do not generate this error.

This works:

code/await Pixel (var int tmp) -> (event none die) -> none do
    await FOREVER;
end

var&? Pixel pixel = spawn Pixel(7);
kill pixel;

_printf("ok\n");
await FOREVER;

This does not work:

code/await Pixel (var int tmp) -> (event none die) -> none do
    await FOREVER;
end

var&? Pixel pixel = spawn Pixel(5); //never works with 5 and 6. Sometimes works with 2
kill pixel;

_printf("ok\n");
await FOREVER;
code/await Pixel (var int tmp) -> none do
    await FOREVER;
end

pool[] Pixel pixels;

par do
    every 1ms do
        spawn Pixel(2) in pixels; //error when using 2, 5 or 6. Other numbers seem to work fine.
    end
with
    var int i=0;
    loop do
        await 2ms;
        var&? Pixel pixel;
        loop pixel in pixels do
            _printf("%d\n",i);
            kill pixel;
            i=i+1;
        end
    end
end