polyscope icon indicating copy to clipboard operation
polyscope copied to clipboard

stack alignment of matrial bindata causes segmentfault

Open YuweiXiao opened this issue 5 years ago • 3 comments

  • code

polyscope::init(); polyscope::show();

  • output

[polyscope] Backend: openGL3_glfw -- Loaded openGL version: 4.1 ATI-3.5.5 [1] 5910 segmentation fault ./demo

  • call stack

exception: stack_not_16_byte_aligned_error stb_image.h: stbi__load_and_postprocess_8bit stb_image.h: stbi__loadf_main stb_image.h: stbi_loadf_from_memory engine.cpp: loadDefaultMaterial engine.cpp: loadDefaultMaterials engine.cpp: allocateGlobalBuffersAndPrograms

  • environment

MacOS Catalina 10.15.3, compiler: apple clang v11

  • workaround

comment out following material load in engine.cpp:

loadDefaultMaterial("mud"); loadDefaultMaterial("ceramic"); loadDefaultMaterial("jade"); loadDefaultMaterial("normal");

YuweiXiao avatar Apr 27 '20 02:04 YuweiXiao

Thank you for the report!

I didn't thing know was possible to trigger stack alignment errors from reasonable C++ code (maybe it's the code is not reasonable?).

I'm guessing this is within your own project---are you using any unusual compiler flags?

I haven't seen this while building/testing before, and don't have a Catalina machine, so this might be hard for me to reproduce. Could you verify that that the issue persists if you either (a) build and run the tests, or (b) build and run the demo app?

nmwsharp avatar Apr 27 '20 15:04 nmwsharp

Thanks for the reply!

I tested the demo and tests. It works and no error reported.

My project is just a toy example trying polyscope. I found the following setting of the c++ flag caused the segment fault.

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -march=native")

By manually setting both the optimization and asking the compiler to choose the native instruction set, the compiled program will meet stack alignment. The same problem happens for the demo app. Removing either (or both) of the flag settings solves the error.

I am not sure why is it. But I guess it is not a good practice to specify optimization level manually.

YuweiXiao avatar Apr 28 '20 01:04 YuweiXiao

Hmmmm, I think those flags should be safe, so there may still be a Polyscope issue here, perhaps an alignment problem with those material buffers. It could also be the case that the march=native flag isn't getting propagated to the dependencies correctly, leading to alignment issues when linking. I can try to reproduce the crash with those flags.

nmwsharp avatar May 07 '20 16:05 nmwsharp

Closing old issue. Feel free to reopen if it's still an issue.

nmwsharp avatar Mar 26 '23 22:03 nmwsharp