Ошибка памяти в многопоточном режиме Bullet3: простой примерC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Ошибка памяти в многопоточном режиме Bullet3: простой пример

Сообщение Anonymous »

Я экспериментирую с многопоточностью Bullet. В следующем простом примере я получаю сообщение об ошибке неизвестного адреса. btCollisionConfiguration инициализируется правильно, и я был бы признателен за понимание проблемы. вот код:

Код: Выделить всё

#include 
#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolverMt.h"
#include "BulletCollision/CollisionDispatch/btCollisionDispatcherMt.h"
#include "BulletCollision/BroadphaseCollision/btDbvtBroadphase.h"
#include "BulletCollision/CollisionShapes/btBoxShape.h"
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"

int main() {
auto collisionConfig = std::make_unique();
auto dispatcher = std::make_unique(collisionConfig.get());
auto broadphase = std::make_unique();
auto solver = std::make_unique();

auto dynamicsWorld = std::make_unique(dispatcher.get(), broadphase.get(), solver.get(), collisionConfig.get());
dynamicsWorld->setGravity(btVector3(0, -10, 0));

auto boxShape = std::make_unique(btVector3(1, 1, 1));
btScalar mass = 1.0;
btVector3 localInertia(0, 0, 0);
boxShape->calculateLocalInertia(mass, localInertia);
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0, 50, 0));
auto motionState = std::make_unique(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState.get(), boxShape.get(), localInertia);
auto body = std::make_unique(rbInfo);
dynamicsWorld->addRigidBody(body.get());

for (int i = 0; i < 100;  ++i) {
dynamicsWorld->stepSimulation(1.f / 60.f, 10);
}

return 0;
}
вот мой файл Cmake:

Код: Выделить всё

cmake_minimum_required(VERSION 3.10)
project(PhysicsSimulation)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

find_package(Bullet REQUIRED)

add_executable(PhysicsSimulation PerformanceTest.cpp)

target_include_directories(PhysicsSimulation PUBLIC ${BULLET_INCLUDE_DIRS})

target_link_libraries(PhysicsSimulation PUBLIC ${BULLET_LIBRARIES})

target_compile_definitions(PhysicsSimulation PUBLIC BT_USE_DOUBLE_PRECISION)

set_target_properties(PhysicsSimulation PROPERTIES
DEBUG_POSTFIX "_Debug"
MINSIZEREL_POSTFIX "_MinsizeRel"
RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo"
)
Вот ошибка:

Код: Выделить всё

AddressSanitizer:DEADLYSIGNAL
=================================================================
==45038==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000105458a54 bp 0x00016b02a970 sp 0x00016b02a920 T0)
==45038==The signal is caused by a READ memory access.
==45038==Hint: address points to the zero page.
#0 0x105458a54 in btCollisionDispatcherMt::btCollisionDispatcherMt(btCollisionConfiguration*, int)+0x6c (libBulletCollision.3.26.dylib:arm64+0x18a54)
#1 0x104dda3c4 in std::__1::__unique_if::__unique_single std::__1::make_unique[abi:ue170006](btDefaultCollisionConfiguration*&&) unique_ptr.h:689
#2 0x104dd9158 in main PerformanceTest.cpp:11
#3 0x19236a0dc  ()

==45038==Register values:
x[0] = 0x0000000000000000   x[1] = 0x0000000000000023   x[2] = 0x0000000000000023   x[3] = 0x0000000105000010
x[4] = 0x0000000105000280   x[5] = 0x0000000000000000   x[6] = 0x000000016a830000   x[7] = 0x0000000000000001
x[8] = 0x0000000105292000   x[9] = 0x0000000000005170  x[10] = 0x0000000000000005  x[11] = 0x00000000ffffffff
x[12] = 0x0000000000000000  x[13] = 0xa11de761ea9f2253  x[14] = 0x0000000000007e01  x[15] = 0x0000000000000006
x[16] = 0x0000000105286f0c  x[17] = 0x0000000105a440b8  x[18] = 0x0000000000000000  x[19] = 0x0000000105000200
x[20] = 0x0000000105005350  x[21] = 0x0000000105005370  x[22] = 0x0000000000000028  x[23] = 0x0000000105005354
x[24] = 0x000000016b02b450  x[25] = 0x00000001923de2db  x[26] = 0x0000000000000000  x[27] = 0x0000000000000000
x[28] = 0x0000000000000000     fp = 0x000000016b02a970     lr = 0x0000000105458a54     sp = 0x000000016b02a920
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (libBulletCollision.3.26.dylib:arm64+0x18a54) in btCollisionDispatcherMt::btCollisionDispatcherMt(btCollisionConfiguration*, int)+0x6c
==45038==ABORTING
zsh: abort      ./PhysicsSimulation_Debug

Также учтите, что на компьютере установлен чип M3. Я попытался проверить адресную память, но инициализация btCollisionDispatcherMt не удалась. Я не уверен, связано ли это с плохой настройкой Bullet3 в моем коде или с недостающими частями при построении SDK. Обратите внимание, что я собрал SDK в режиме двойной точности.

Подробнее здесь: https://stackoverflow.com/questions/784 ... le-example
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»