質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
g++

g++はGNUコンパイラコレクション(gcc)のC++コンパイラーです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

0回答

288閲覧

[Bullet physics] malloc.c:2379: sysmalloc: Assertion の原因が知りたい

samidare_chan

総合スコア16

g++

g++はGNUコンパイラコレクション(gcc)のC++コンパイラーです。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2023/12/14 09:47

質問内容

提示コードですがコンパイルしてビルドするために以下のコマンドを実行して実行ファイルを実行すると以下のエラーコードが出ます。
この原因がわかりません。

知りたいこと

何が原因で何をすればいいのか知りたい

調べたこと

printf()でどこが原因なのか突き止めようとしましたが一番上に置いても出力されないため原因が追求できません。
参考サイト(回答なし):https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=12458
ChatGDTにて質問

このエラーは、メモリアロケーションに関連する問題を示しています。通常、この種のエラーは以下のいずれかの理由によるものです。 メモリの過度な使用: プログラムが予期せず多くのメモリを使用しすぎて、メモリの不足や破損が発生した可能性があります。 メモリのダブル解放: プログラムで同じメモリ領域が二度解放されている可能性があります。これはプログラム内のバグによるものです。 メモリ領域のオーバーフロー: メモリ領域外へのアクセスやオーバーフローが発生している可能性があります。
環境

OS: ubuntu
コンパイラ: g++
利用ライブラリ: bullet physics_イタリックテキスト_

実行コマンド
$ g++ Main.cpp -lLinearMath -lBulletDynamics -lBulletCollision -I /usr/local/include/bullet/ $ ./a.out
エラーコード
$ ./a.out a.out: malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed. 中止 (コアダンプ)
ソースコード

cpp

1/* 2Bullet Continuous Collision Detection and Physics Library 3Copyright (c) 2003-2007 Erwin Coumans https://bulletphysics.org 4 5This software is provided 'as-is', without any express or implied warranty. 6In no event will the authors be held liable for any damages arising from the use of this software. 7Permission is granted to anyone to use this software for any purpose, 8including commercial applications, and to alter it and redistribute it freely, 9subject to the following restrictions: 10 111. 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. 122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 133. This notice may not be removed or altered from any source distribution. 14*/ 15 16///-----includes_start----- 17#include "btBulletDynamicsCommon.h" 18#include <stdio.h> 19 20/// This is a Hello World program for running a basic Bullet physics simulation 21 22int main() 23{ 24 printf("aaaa"); 25 ///-----includes_end----- 26 27 int i; 28 ///-----initialization_start----- 29 30 ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration. 31 btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); 32 33 ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) 34 btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); 35 36 ///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep. 37 btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase(); 38 39 ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) 40 btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; 41 42 btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration); 43 44 dynamicsWorld->setGravity(btVector3(0, -10, 0)); 45 46 ///-----initialization_end----- 47 48 //keep track of the shapes, we release memory at exit. 49 //make sure to re-use collision shapes among rigid bodies whenever possible! 50 btAlignedObjectArray<btCollisionShape*> collisionShapes; 51 52 ///create a few basic rigid bodies 53 54 //the ground is a cube of side 100 at position y = -56. 55 //the sphere will hit it at y = -6, with center at -5 56 { 57 btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.), btScalar(50.), btScalar(50.))); 58 59 collisionShapes.push_back(groundShape); 60 61 btTransform groundTransform; 62 groundTransform.setIdentity(); 63 groundTransform.setOrigin(btVector3(0, -56, 0)); 64 65 btScalar mass(0.); 66 67 //rigidbody is dynamic if and only if mass is non zero, otherwise static 68 bool isDynamic = (mass != 0.f); 69 70 btVector3 localInertia(0, 0, 0); 71 if (isDynamic) 72 groundShape->calculateLocalInertia(mass, localInertia); 73 74 //using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects 75 btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); 76 btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia); 77 btRigidBody* body = new btRigidBody(rbInfo); 78 79 //add the body to the dynamics world 80 dynamicsWorld->addRigidBody(body); 81 } 82 83 { 84 //create a dynamic rigidbody 85 86 //btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1)); 87 btCollisionShape* colShape = new btSphereShape(btScalar(1.)); 88 collisionShapes.push_back(colShape); 89 90 /// Create Dynamic Objects 91 btTransform startTransform; 92 startTransform.setIdentity(); 93 94 btScalar mass(1.f); 95 96 //rigidbody is dynamic if and only if mass is non zero, otherwise static 97 bool isDynamic = (mass != 0.f); 98 99 btVector3 localInertia(0, 0, 0); 100 if (isDynamic) 101 colShape->calculateLocalInertia(mass, localInertia); 102 103 startTransform.setOrigin(btVector3(2, 10, 0)); 104 105 //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects 106 btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); 107 btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, colShape, localInertia); 108 btRigidBody* body = new btRigidBody(rbInfo); 109 110 dynamicsWorld->addRigidBody(body); 111 } 112 113 /// Do some simulation 114 115 ///-----stepsimulation_start----- 116 for (i = 0; i < 150; i++) 117 { 118 dynamicsWorld->stepSimulation(1.f / 60.f, 10); 119 120 //print positions of all objects 121 for (int j = dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) 122 { 123 btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j]; 124 btRigidBody* body = btRigidBody::upcast(obj); 125 btTransform trans; 126 if (body && body->getMotionState()) 127 { 128 body->getMotionState()->getWorldTransform(trans); 129 } 130 else 131 { 132 trans = obj->getWorldTransform(); 133 } 134 printf("world pos object %d = %f,%f,%f\n", j, float(trans.getOrigin().getX()), float(trans.getOrigin().getY()), float(trans.getOrigin().getZ())); 135 } 136 } 137 138 ///-----stepsimulation_end----- 139 140 //cleanup in the reverse order of creation/initialization 141 142 ///-----cleanup_start----- 143 144 //remove the rigidbodies from the dynamics world and delete them 145 for (i = dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--) 146 { 147 btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i]; 148 btRigidBody* body = btRigidBody::upcast(obj); 149 if (body && body->getMotionState()) 150 { 151 delete body->getMotionState(); 152 } 153 dynamicsWorld->removeCollisionObject(obj); 154 delete obj; 155 } 156 157 //delete collision shapes 158 for (int j = 0; j < collisionShapes.size(); j++) 159 { 160 btCollisionShape* shape = collisionShapes[j]; 161 collisionShapes[j] = 0; 162 delete shape; 163 } 164 165 //delete dynamics world 166 delete dynamicsWorld; 167 168 //delete solver 169 delete solver; 170 171 //delete broadphase 172 delete overlappingPairCache; 173 174 //delete dispatcher 175 delete dispatcher; 176 177} 178

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

lrstatus

2023/12/16 13:45

プロセス実行に許されているリソース(スタック、データ領域、仮想メモリなど)のサイズが足りてないということはないでしょうか。 使用シェルがbashなら ulimit -a で現在の設定値を調べて見てはどうでしょうか
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問