PavelBlend / blender-molecular

molecular addon for blender
26 stars 7 forks source link

with a search length bigger than 3 it will crash most of the time #6

Closed OmidGhotbi closed 5 months ago

OmidGhotbi commented 6 months ago

with a search length bigger than 3 it will crash most of the time

PavelBlend commented 6 months ago

@OmidGhotbi try using the new version I added today:

https://github.com/PavelBlend/blender-molecular/releases/tag/v1.2.0

OmidGhotbi commented 6 months ago

I can confirm it is far more stable than before. thank you.

i added some error management code to see if i can find why sometimes it crashes and i noticed sometimes malloc points to null and can not reserve the memory that it needs. maybe that's help.

    kdtree->numnodes = i;
    kdtree->nodes = (Node*) malloc((kdtree->numnodes + 1) * sizeof(Node));
    if (kdtree->nodes == NULL) {
        fprintf(stderr, "Failed to allocate memory for nodes.\n");
        exit(1);
    }
    kdtree->root_node = (Node*) malloc(sizeof(Node));
    if (kdtree->root_node == NULL) {
        fprintf(stderr, "Failed to allocate memory for root_node.\n");
        exit(1);
    }

    for (int i=0; i<kdtree->numnodes; i++) {
        kdtree->nodes[i].index = i;
        kdtree->nodes[i].name = -1;
        kdtree->nodes[i].parent = -1;

        kdtree->nodes[i].particle = (SParticle*) malloc(sizeof(SParticle));
        if (kdtree->nodes[i].particle == NULL) {
            fprintf(stderr, "Failed to allocate memory for nodes_particle.\n");
            exit(1);
        }

        kdtree->nodes[i].left_child = (Node*) malloc(sizeof(Node));
        if (kdtree->nodes[i].left_child == NULL) {
            fprintf(stderr, "Failed to allocate memory for nodes_left_child.\n");
            exit(1);
        }
        kdtree->nodes[i].right_child = (Node*) malloc(sizeof(Node));
        if (kdtree->nodes[i].right_child == NULL) {
            fprintf(stderr, "Failed to allocate memory for nodes_right_child.\n");
            exit(1);
        }
        kdtree->nodes[i].left_child[0].index = -1;
        kdtree->nodes[i].right_child[0].index = -1;
    }
OmidGhotbi commented 6 months ago

Crash on the high-resolution grid, i need to mention although it's more stable, the crash caused by the search link Redius is related ti voxel size. with a voxel size of 30 and a search link of 3.5, it's fine. but if I have more resolutions of 50 or more it will start crashing at 3.5 and I need to change it to 2, same with 120 resolution it will start to crash at search link 1.0 So it's related to the voxel size.

PavelBlend commented 5 months ago

How often does it crash? I've now baked a simulation at 50 resolution and have had no crashes. My simulation has 100 frames. Previously, I also baked the simulation at a higher resolution and there were no glitches. 01

OmidGhotbi commented 5 months ago

i'm using simulation, i did not test bake yet. when I have link, break and relink active crash will happen most of the time. i did a fix that I'm trying to commit that fix most of the crash. Screenshot 2024-04-12 112414 Screenshot 2024-04-12 112303

OmidGhotbi commented 5 months ago

Fixed.