VulkanMemoryAllocator icon indicating copy to clipboard operation
VulkanMemoryAllocator copied to clipboard

Segfault on call to vmaCreateAllocator() when using c++11

Open mjdave opened this issue 8 months ago • 7 comments

This is on a raspberry pi 5, clean and up to date, VMA 3.2.1.

I had a consistent segfault on line 12928 in the VmaAllocator_T constructor, called via 15075, and was able to fix it by changing from c++11 to c++17 with set (CMAKE_CXX_STANDARD 17) in my project's CMakeLists.txt.

I'm sorry I don't know enough about c++ to help further, but thought this might be useful, and it could maybe give a compile error instead of a runtime one. Thanks.

mjdave avatar Mar 26 '25 19:03 mjdave

I doubt this is a bug in VMA, but to investigate it further, I would need to know more details about what exactly is crashing and why.

adam-sawicki-a avatar Mar 27 '25 08:03 adam-sawicki-a

Are you using Visual Studio? Can you maybe give a callstack or some more information?

IAmNotHanni avatar Mar 28 '25 15:03 IAmNotHanni

It's using cmake on a raspberry pi (not visual studio), and it crashes on line 12928 via line 15076 (sorry I mistakingly said 15075) if I use set (CMAKE_CXX_STANDARD 11), and doesn't crash at all if use set (CMAKE_CXX_STANDARD 17).

For my purposes, I can just use C++17, I am not concerned, I just lost a couple of hours before I stumbled on this workaround, but the actual cause or fix is beyond me.

Here is my backtrace:

Thread 1 "ambience" received signal SIGSEGV, Segmentation fault. 0x0000000000503580 in VmaAllocator_T::VmaAllocator_T (this=0x0, pCreateInfo=0x7fffffffe8a0) at /home/dave/ambience/pi/../thirdParty/VulkanMemoryAllocator-3.2.1/include/vk_mem_alloc.h:12928 12928 m_hInstance(pCreateInfo->instance), (gdb) bt #0 0x0000000000503580 in VmaAllocator_T::VmaAllocator_T (this=0x0, pCreateInfo=0x7fffffffe8a0) at /home/dave/ambience/pi/../thirdParty/VulkanMemoryAllocator-3.2.1/include/vk_mem_alloc.h:12928 #1 0x0000000000503adc in vmaCreateAllocator (pAllocator=0x71d4e8, pCreateInfo=0x7fffffffe8a0) at /home/dave/ambience/pi/../thirdParty/VulkanMemoryAllocator-3.2.1/include/vk_mem_alloc.h:15076 #2 Vulkan::createVMA (this=this@entry=0x71d4d0) at /home/dave/ambience/core/Vulkan.cpp:658 #3 0x000000000050fcc0 in Vulkan::Vulkan (this=this@entry=0x71d4d0, controller_=controller_@entry=0x6deb70, window_=<optimized out>, screenSize=..., vsync_=<optimized out>) at /home/dave/ambience/core/Vulkan.cpp:208 #4 0x00000000004d92c4 in MainController::MainController (this=this@entry=0x6deb70) at /home/dave/ambience/core/MainController.cpp:621 #5 0x0000000000462ffc in main (argc=<optimized out>, argv=<optimized out>) at /home/dave/ambience/pi/main.cpp:17 (gdb)

This is my CMakeLists.txt in case it helps

CMakeLists.txt

mjdave avatar Mar 28 '25 21:03 mjdave

I guess it's not really the C++ standard that is used for compiling the program which causes problems in the code, it's more likely that there's some #if block which decides which features to use depending on the used C++ standard. I guess without any code, this will be very hard to debug for us. One thing that peaks out thouth is that the this pointer seems to be nullptr: (this=0x0, pCreateInfo=0x7fffffffe8a0).

IAmNotHanni avatar Mar 28 '25 21:03 IAmNotHanni

Can you paste the code you use to call vmaCreateAllocator? Could it be that you forgot to set .instance in VmaAllocatorCreateInfo ?

IAmNotHanni avatar Mar 28 '25 21:03 IAmNotHanni

It could actually be an issue with the Vulkan loader code! How do you load Vulkan functions? Do you statically link against Vulkan lib or do you load them dynamically using a library like volk? If that is the case, it might be a bug in volk.

IAmNotHanni avatar Mar 28 '25 21:03 IAmNotHanni

Please also make sure that VMA_ASSERT is defined to something that will report an error rather than be ignored. That can help in debugging these kinds of issues.

adam-sawicki-a avatar Mar 31 '25 07:03 adam-sawicki-a