ithron / CortidQCT

A tool for automatic cortical shape identification for QCT scans
Academic Free License v3.0
2 stars 0 forks source link

Matlab crashes on Mesh.rayIntersections() #59

Closed ithron closed 5 years ago

ithron commented 5 years ago

When calling Mesh.rayIntersection() with a large number of rays, MATLAB crashes when exiting the function.

ithron commented 5 years ago

This is probably because the matlab struct does not have the same padding as the C struct.

ithron commented 5 years ago

I've padded the matlab struct in the same way as the C struct and checked that the number of bytes copie are correct. But it still crashes. So that's not the problem (at least not the only one).

ithron commented 5 years ago

The intersesting thing ist, that matlab does even crash when the C function is not called at all. Maybe matlab tries to free the pointer after the last iteration, but because pointer arithmetic was used, it points to one element pas the last memory address, resulting in freeing in invalid address. This would be an absolute stupid bug in matlab.

ithron commented 5 years ago

Even when the C code is allocating the memory, matlab crashes when it leaves the function. Seems to be an issue with libstruct.

Workaround: Make a special C functin just for the matlab API that writes the entries of the CQCT_RayMeshIntersection_t struct to single buffers. This also simplifies the matlab wrapper code a lot.