ABRG-Models / morphologica

A library of supporting code for numerical modelling (JSON config, HDF5 data, Modern OpenGL visualization)
https://abrg-models.github.io/morphologica/
Apache License 2.0
255 stars 29 forks source link

Segmentation fault in morph::GridVisual::initializeVerticesRectsInterpolated when running grid_image example #182

Closed SeverinDenisenko closed 6 months ago

SeverinDenisenko commented 6 months ago

There is probably something wrong with indexes.

morph::Visual<glver=4.1> version 3.0 running on OpenGL Version 4.6 (Core Profile) Mesa 23.3.6
Image dims: (256,65)

Thread 1 "grid_image" received signal SIGSEGV, Segmentation fault.
0x0000000000521426 in morph::GridVisual<float, unsigned int, float, 262145>::initializeVerticesRectsInterpolated (this=0x61a0002a7280)
    at morphologica/morph/GridVisual.h:273
273                     datumNN =  this->grid->has_nn(ri)  ? dcopy[this->grid->index_nn(ri)] : datumC;
(gdb) bt
#0  0x0000000000521426 in morph::GridVisual<float, unsigned int, float, 262145>::initializeVerticesRectsInterpolated (this=0x61a0002a7280)
    at morphologica/morph/GridVisual.h:273
#1  0x0000000000529285 in morph::GridVisual<float, unsigned int, float, 262145>::initializeVertices (this=<optimized out>) at morphologica/morph/GridVisual.h:77
#2  0x000000000040b763 in morph::VisualModel<262145>::finalize (this=0x61a0002a7280) at morphologica/morph/VisualModel.h:234
#3  main () at morphologica/examples/grid_image.cpp:67

With ASAN:

morph::Visual<glver=4.1> version 3.0 running on OpenGL Version 4.6 (Core Profile) Mesa 23.3.6
Image dims: (256,65)
AddressSanitizer:DEADLYSIGNAL
=================================================================
==62817==ERROR: AddressSanitizer: SEGV on unknown address 0x631400244400 (pc 0x000000521426 bp 0x7ffd664c49d0 sp 0x7ffd664c4030 T0)
==62817==The signal is caused by a READ memory access.
    #0 0x521426 in morph::GridVisual<float, unsigned int, float, 262145>::initializeVerticesRectsInterpolated() morphologica/morph/GridVisual.h:273
    #1 0x529284 in morph::GridVisual<float, unsigned int, float, 262145>::initializeVertices() morphologica/morph/GridVisual.h:77
    #2 0x40b762 in morph::VisualModel<262145>::finalize() morphologica/morph/VisualModel.h:236
    #3 0x40b762 in main morphologica/examples/grid_image.cpp:67
    #4 0x7f9518965149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
    #5 0x7f951896520a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
    #6 0x40cb54 in _start (morphologica/build/examples/grid_image+0x40cb54) (BuildId: 85b89c3aa6d2f950289596e37e767f29e1c3c3a4)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV morphologica/morph/GridVisual.h:273 in morph::GridVisual<float, unsigned int, float, 262145>::initializeVerticesRectsInterpolated()
==62817==ABORTING

Found on last main branch.

sebjameswml commented 6 months ago

Confirmed, I get this bug too.

sebjameswml commented 6 months ago

The bug is in morph/Grid.h. I'll get it fixed soon.

sebjameswml commented 6 months ago

This should be resolved with the associated pull request. I'll close once it has passed its CI.