#Bizzare segfault only appearning in non-gdb context

133 messages · Page 1 of 1 (latest)

rough crypt
#

Ok, I'm thoroughly stumped on this one and I need to go to bed.

// Calling vmaCreateBuffer
std::cerr << "Before vmaCreateBuffer" << std::endl;

// Temporarily ignoring return value
vmaCreateBuffer(
    device.getAllocator(), // prints the returning allocator
    &bufferCreateInfo, // non null
    &bufferAllocationCreateInfo, // non null
    &this->buffer, // non null
    &this->buffer_allocation, // non null
    nullptr
);

std::cerr << "After vmaCreateBuffer" << std::endl;
seb::panic("CREATED BUFFER SHUTDOWN");
// Slightly modified vmaCreateBuffer
VMA_CALL_PRE VkResult VMA_CALL_POST vmaCreateBuffer(
    VmaAllocator allocator,
    const VkBufferCreateInfo* pBufferCreateInfo,
    const VmaAllocationCreateInfo* pAllocationCreateInfo,
    VkBuffer* pBuffer,
    VmaAllocation* pAllocation,
    VmaAllocationInfo* pAllocationInfo)
{
    std::cerr << "Inside vmaCreateBuffer" << std::endl; // added
    VMA_ASSERT(allocator && pBufferCreateInfo && pAllocationCreateInfo && pBuffer && pAllocation);
...

Output (normal):

Before vmaCreateBuffer
[Jan 01/01/2023 03:20:12.938:484 AM] [src/render/renderer.cpp:143:47] [Fatal] Before Object Creation
Before vmaCreateBuffer
[Jan 01/01/2023 03:20:12.938:941 AM] [src/render/device.hpp:176:49] [Fatal] Returning allocator!
PS C:\Users\samsk\Desktop\sebgen-vkhp\build> 

using gdb:

[Jan 01/01/2023 03:20:43.365:784 AM] [src/render/renderer.cpp:143:47] [Fatal] Before Object Creation
Before vmaCreateBuffer
[Jan 01/01/2023 03:20:43.366:251 AM] [src/render/device.hpp:176:49] [Fatal] Returning allocator!
After vmaCreateBuffer
Thread panic! id: 1 | [Jan 01/01/2023 03:20:43.367:771 AM] [src/render/buffer.cpp:111:53] [Fatal] CREATED BUFFER SHUTDOWN

I have absolutely no idea what is going on here. Why does it work inside of gdb and not normally. Why does putting a function call in the beginning of vmaCreateBuffer not get called?

stark gyroBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

rough crypt
#

Even weirder. if I remove all the debug helping bits. in gdb, it returns a valid buffer and the whole program works just fine, however if I run manually(not in gdb) that weird not calling vmaCreateBuffer behavior happens and I get a segfault. I am at my wits end

#

Also since I am using mingw's version of g++ I am not currently getting a core dump, does anyone know if that is possible on windows or do I need to be running something linux based to get a core dump.

#

Using drmingw I was able to get a backtrace and I can see that It's going into VmaAllocator_T::GetBufferMemoryRequirements however that still doesnt explain why the std cerr with a flush isnt printing to stdout

#

Sorry for all the screenshots the messages are too long for discord

#

Any and all help will be appreciated, I probably won't be responding until about 8AM EST / 1PM UTC

fleet sierra
#

Try to compile with -fsanitize=undefined,address and see if you get a (better) diagnosis.

rough crypt
#

hmmmm, It appears if I comment out the function it still links just fine. I am linking a static library with this header how can O figure out wiich functions ir provides to the linker?

fleet sierra
#

Are you using an ancient version? Worked fine for me using 8.3 I think, the one that the Qt Creator maintenance tool installs.

rough crypt
#

nope im using g++-12

#

and right now my thing wont even build with clang since im using like std::source_location && std::jthread and stoptoken

#

those are c++ 20 features clang doeesnt have yet

#

I feel I have two options:
Install linux on my mac and get a proper installation of gcc with sanitizers and hope for the best
Attempt to use msvc with visual studio.

Do you have any other ideas?

fleet sierra
#

Install a gcc with sanitizers. I guess you could also just install 🐧 properly.

rough crypt
#

mingw which is how you get g++ with sanitizers just flat out doesnt work on windows

#

its in progress and they have to be built by msvc and you have to build them from source

fleet sierra
#

Hmm, maybe I just dreamed that it worked on Window 🤔

rough crypt
#

I took a look at qt creator and it says nothing about sanitizer support, perhaps you were confusing a time you used gdb?

#

idk

#

this is hands down the weirdest segfault ive ever delt with

fleet sierra
#

If you have 30GB or so disk space left a VM on Windows should do it.

rough crypt
#

I forgor about virtual machines

#

time to download virtual box

fleet sierra
rough crypt
#

Thats what im concerned about

#

oh

fleet sierra
#

Worth a try though.

rough crypt
#

wait

#

listen to this

rough crypt
#

how can I dump the static library file and see what it provides to the linker

fleet sierra
#

I forgot. There is objectdump and the other one.

rough crypt
#

because it seems I am defining a different function when I make changes directly to the header

#

since I can remove it and it still compiles

fleet sierra
#

objdump -TCw was one and nm -gC another, depending on ... something.

#

I think one was for object files and the other for archive files.

#

You could use my LibFinder 😛

rough crypt
#

its being linked by the static lib

#

now why the fUCKKK is is defined in the header

#

oh wait

#

it was create buffer

#

let me check

#

nope same thing

#

its just a few lines down

#

Weird!

#

so why is it defined in the header file and the static library

fleet sierra
#

If it's actually defined in the header it's probably inline which should make the generated object files not ask for the symbol from the static library.

rough crypt
#
    VmaAllocator allocator,
    const VkBufferCreateInfo* pBufferCreateInfo,
    const VmaAllocationCreateInfo* pAllocationCreateInfo,
    VkBuffer* pBuffer,
    VmaAllocation* pAllocation,
    VmaAllocationInfo* pAllocationInfo)```
#

not inlined

#

those macros expand to nothing

fleet sierra
#

Then you should be getting a double definition error when you include the header from 2 source files.

#

Or did you mean declaration?

rough crypt
#

no I mean declaration

#

One thing im going to try is that im including the file but not adding it to my sources in cmake

fleet sierra
#

Well, declaring a function in a header and defining it in a library is how you're supposed to do it, right? I feel like I'm missing some crucial detail.

rough crypt
#

yea thats how its soupossed to be done but for some reason its also being defined in the header so when I include it its causing problems

#

The compiler is never even parsing the function that I can see. I added a #error and nothing happens

fleet sierra
#

I think this header is just trolling you.

rough crypt
#

thats what im thinking

#

Ok, theres some real funky shit going on here. I am just trying to compile the h file and I tried setting everything to always inline and now I can see that the compiler can't find the function bodies in the same file!

C:/Users/samsk/Desktop/sebgen-vkhp/inc/vk_mem_alloc.h:1568:33: error: inlining failed in call to 'always_inline' 'void vmaDestroyAllocator(VmaAllocator)': function body not available
 1568 | VMA_CALL_PRE void VMA_CALL_POST vmaDestroyAllocator(
      |                                 ^~~~~~~~~~~~~~~~~~~
#

but its in the SAME damn file!

#

what

#

time to see if its getting cut out by some macro

#

there we go

#

well this is all my fault since I didnt read the documentation :trolol

Vulkan Memory Allocator comes in form of a "stb-style" single header file.
You don't need to build it as a separate library project.
You can add this file directly to your project and submit it to code repository next to your other source files.

"Single header" doesn't mean that everything is contained in C/C++ declarations,
like it tends to be in case of inline functions or C++ templates.
It means that implementation is bundled with interface in a single file and needs to be extracted using preprocessor macro.
If you don't do it properly, you will get linker errors.

To do it properly:

-# Include "vk_mem_alloc.h" file in each CPP file where you want to use the library.
   This includes declarations of all members of the library.
-# In exactly one CPP file define following macro before this include.
   It enables also internal definitions.

\code
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.h"
\endcode

It may be a good idea to create dedicated CPP file just for this purpose.

This library includes header `<vulkan/vulkan.h>`, which in turn
includes `<windows.h>` on Windows. If you need some specific macros defined
before including these headers (like `WIN32_LEAN_AND_MEAN` or
`WINVER` for Windows, `VK_USE_PLATFORM_WIN32_KHR` for Vulkan), you must define
them before every `#include` of this library.

This library is written in C++, but has C-compatible interface.
Thus you can include and use vk_mem_alloc.h in C or C++ code, but full
implementation with `VMA_IMPLEMENTATION` macro must be compiled as C++, NOT as C.
Some features of C++14 are used. STL containers, RTTI, or C++ exceptions are not used.
#

I never defined that macro

#

and I also compiled it as a static library

#

thus leading to weird error

#

and it stll doesnt work

#

joy

#

what now

#

absolutely brutal

#

thats why it worked in intellisense

fleet sierra
rough crypt
#

exactly

#

just use a damn extern C++ block

#

or extern C

#

Does this error make any sense to you?

#
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/Sebgen.dir/src/render/vertex.cpp.obj: in function `vmaGetVirtualBlockStatistics':
C:/Users/samsk/Desktop/sebgen-vkhp/inc/vk_mem_alloc.h:17488: multiple definition of `vmaGetVirtualBlockStatistics'; CMakeFiles/Sebgen.dir/src/main.cpp.obj:C:/Users/samsk/Desktop/sebgen-vkhp/inc/vk_mem_alloc.h:17488: first defined here
#

@fleet sierra

#

If Im reading this right its getting a multiple definition from the same definition?

#

what

fleet sierra
rough crypt
#

but wouldn't include guards solve that?

#

does this file have include guards?

fleet sierra
#

Did you use the VMA_IMPLEMENTATION macro thing in 2 places?

rough crypt
#

nope

#

its included in one file

#

every thing else includes that file

fleet sierra
#

And that one file is a source file and not a header file?

rough crypt
#

nope it is a header file

#

guessing thats bad

fleet sierra
#

And that header file gets included more than once.

rough crypt
#

but I have include guards in that file.

#

am I misunderstanding include guards?

fleet sierra
#

Include guards don't help with multiple definitions.

#

Include guards work per source file, not per program.

rough crypt
#

oh so I include the header in every file but only enable the definitions in one using the macro

#

thats... strange

fleet sierra
#

Yes

rough crypt
fleet sierra
#

It also makes the suggestion to make a separate source file that only includes the header with the VMA_IMPLEMENTATION seem almost reasonable.

rough crypt
#

hmm

fleet sierra
rough crypt
#

Well now im back to vma not finding some functions

#

im going to do the .cpp file thing

fleet sierra
#

Right, now you have no VMA_IMPLEMENTATION anymore, makes sense.

rough crypt
#

well no, I added in in one cpp file. anyway im just going to make a seperate file

fleet sierra
#

Maybe buffer.hpp already includes it and now header guards are screwing you over :D

rough crypt
#

Thanks for being patient and helping me out, I wouldn't be able to figure this shit out on my own lol

#

holy crap it linked

#

I dont think ive ever been so excited to have a program that segfaults

stark gyroBOT
#

@rough crypt Has your question been resolved? If so, run !solved :)

rough crypt
#

not yet lmfao Wheately, I still wonder how the bot does this

#

holy fuckl

#

I have my rotating square

#

@fleet sierra Thank you so so so much.

#

!solved

stark gyroBOT
#

Thank you and let us know if you have any more questions!