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

shapes: Crash when creating shapes with many removed vertices #20

Closed
phed opened this issue Mar 14, 2017 · 2 comments
Closed

shapes: Crash when creating shapes with many removed vertices #20

phed opened this issue Mar 14, 2017 · 2 comments
Labels

Comments

@phed
Copy link

phed commented Mar 14, 2017

Example:
shape = par_shapes_create_torus(40, 40, 0.8);

While the crash itself happens deep inside the code (a triangle with a uninitialized value) the problem is caused around par_shapes.h#L1678 :

    for (int p = 0; p < mesh->npoints; p++, src += 3) {
        if (weldmap[p] == p) {
            *dst++ = src[0];
            *dst++ = src[1];
            *dst++ = src[2];
            *cmap++ = ci++;
        } else {
            // NOTE(phed) 
            // Example: p == 556, weldmap[p] == 563
            // condensed_map[weldmap[p]] == uninitialized
            // assert(weldmap[p] < p); // Seems to reliably detect when the error is about to happen
            *cmap++ = condensed_map[weldmap[p]];
        }

A non-fix, but code that seemingly works, I am not sure how to do it in a single pass, so I resorted to a magic number to work around it:

    for (int p = 0; p < mesh->npoints; p++, src += 3) {
        if (weldmap[p] == p) {
            *dst++ = src[0];
            *dst++ = src[1];
            *dst++ = src[2];
            *cmap++ = ci++;
        } else {
            *cmap++ = 65535;
        }
    }
    cmap = condensed_map;
    for (int p = 0; p < mesh->npoints; p++) {
        if (*cmap == 65535) {
            *cmap = condensed_map[weldmap[p]];
        }
        cmap++;
    }
@sonoro1234
Copy link
Contributor

sonoro1234 commented Aug 17, 2018

@phed I am not getting a crash for par_shapes_create_torus(40, 40, 0.8);
perhaps you compiled with ffast-math?

@prideout
Copy link
Owner

Unable to repro. A more correct assert would be:

assert(weldmap[p] < mesh->npoints)

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

No branches or pull requests

3 participants