Segmentation Fault during btDiscreteDynamicsWorld Constructor (btAllocDefault) (TDM-GCC-64)

Post Reply
Posts: 7
Joined: Sun Aug 04, 2013 8:44 pm

Segmentation Fault during btDiscreteDynamicsWorld Constructor (btAllocDefault) (TDM-GCC-64)

Post by MajorNr01 » Mon Nov 12, 2018 8:05 pm

I compiled Bullet on Windows 7 into static libraries using cmake and TDM-GCC-64.

Has anyone else used Bullet with the TDM-GCC-64 compiler on Windows? If no one knows what's going on I would at least appreciate to know who has.

For testing purposes I simplified my usage to the following source code:

Code: Select all

#include <iostream>

#include "btBulletDynamicsCommon.h"

int main()
    std::cout << "Hello World!" << std::endl;
    btDefaultCollisionConfiguration* cc = new btDefaultCollisionConfiguration();
    btCollisionDispatcher* cd = new btCollisionDispatcher(cc);
    btBroadphaseInterface* bi = new btDbvtBroadphase();
    btSequentialImpulseConstraintSolver* cs = new btSequentialImpulseConstraintSolver;
    btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(cd, bi, cs, cc);
    std::cout << "Bye World!" << std::endl;
    delete dynamicsWorld;
    delete cs;
    delete bi;
    delete cd;
    delete cc;
    return 0;

Compiling and running this in the GDB64 debugger it segmentation faults with this stack trace:

Code: Select all

1  ntdll!RtlAllocateHeap                                                            0x76e7f9b5    
2  ntdll!RtlAllocateHeap                                                            0x76e7f4dc    
3  ntdll!EtwEventWriteStartScenario                                                 0x76f03cfd    
4  ntdll!RtlIsDosDeviceName_U                                                       0x76ea4985    
5  ntdll!RtlAllocateHeap                                                            0x76e7f4dc    
6  msvcrt!malloc                                                                    0x7fefdbf13d2 
7  btAllocDefault                                   btAlignedAllocator.cpp      24  0x457c95      
8  btAlignedAllocDefault                            btAlignedAllocator.cpp      70  0x457ce6      
9  btAlignedAllocInternal                           btAlignedAllocator.cpp      251 0x457e1b      
10 btDiscreteDynamicsWorld::btDiscreteDynamicsWorld btDiscreteDynamicsWorld.cpp 228 0x40af3a      
11 main                                             main.cpp                    14  0x401697      
pointing me to btAlignedAllocator.cpp line 24:

Code: Select all

Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans

This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

#include "btAlignedAllocator.h"

int gNumAlignedAllocs = 0;
int gNumAlignedFree = 0;
int gTotalBytesAlignedAllocs = 0;//detect memory leaks

static void *btAllocDefault(size_t size)
	return malloc(size); // <- THIS IS WHERE IT FAULTS ////////////////////////////////////////////////////////////////////////////

static void btFreeDefault(void *ptr)

static btAllocFunc *sAllocFunc = btAllocDefault;
static btFreeFunc *sFreeFunc = btFreeDefault;


I see a few possibilities:

1. This is compiler related, i.e., TDM-GCC compiling for x64 does some weird/buggy stuff
2. GDB points me to the wrong place because I built the static libraries wrong for debugging
3. I am actually using Bullet wrong (???)
4. Something else entirely

As an aside, I have had trouble building things like Extras and Demos because they use 'snprints_s' or something which is only available in msvc and not MinGW, despite '_WIN32' being defined. This may or may not relate to this problem.

Also, my IDE is QtCreator.

Thanks for your help.

Post Reply