Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "kill" command makes application terminates unexpectedly #141

Open
AnnyCaroline opened this issue May 9, 2019 · 2 comments
Open

Use "kill" command makes application terminates unexpectedly #141

AnnyCaroline opened this issue May 9, 2019 · 2 comments

Comments

@AnnyCaroline
Copy link
Member

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.

@AnnyCaroline
Copy link
Member Author

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;

@AnnyCaroline
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant