Crash when using atomic operation on SSBO

Hey. Why my program crahes when i try using atomic addition on SSBO integer.
Here is my code:

layout(rgba8, binding = 0) uniform image3D Voxels;
layout(std430, binding=0) buffer List {
   int size;
   ivec4 coords[];
void main () {
   if (imageLoad(Voxels, ivec3(SOME_POSITION)).a == 0.0) {
       imageStore(Voxels, ivec3(SOME_POSITION), VOXEL_FLUX);
       atomicAdd(size, 1);
       atomicAdd(coords[size].x, int(SOME_POSITION.x));
       atomicAdd(coords[size].y, int(SOME_POSITION.y));
       atomicAdd(coords[size].z, int(SOME_POSITION.z));

Program crashes because of the line - ‘atomicAdd(size, 1)’. What is the problem?

You haven’t really provided enough information. Did you allocate and bind the SSBO properly before dispatch? Did you allocate enough space to account for worst-space growth?

One obvious problem: you’re incorrectly assuming that after incrementing size, it won’t change in the rest of that invocation. atomicAdd() returns the old value to avoid this problem. You probably should be using that as the index instead.

Also, be sure to read:

Thanks for reply. Yeah i ve done everything before allright (i guess).Here is the code

glBindBuffer(GL_SHADER_STORAGE_BUFFER, voxels_list);
glBufferData(GL_SHADER_STORAGE_BUFFER, 16 + 16777216, NULL, GL_DYNAMIC_COPY); // MORE than enough space

glBindImageTexture(0, voxels_color, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA8);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, voxels_list);