eugene.litvinov Posted February 11, 2011 Share Posted February 11, 2011 I create JointFixed through Unigine script: joint = class_remove(new JointFixed(innerBodyDummy, body, object.getPosition())); Then I need to delete this joint, I do next: delete joint; And get error: 7:14:08 ExternClass::destructor(): object is not constructed17:14:08 Stack dump: 17:14:08 0x0000: Source::Player 00000000042CE390 (1245185:0:0) 17:14:08 0x0001: vec4: 1.4013e-045 -1.#QNAN -1.#QNAN -1.#QNAN 17:14:08 0x0002: Source::Game 00000000042CE340 (1245199:0:0) 17:14:08 0x0003: vec4: 1.4013e-045 -1.#QNAN -1.#QNAN -1.#QNAN 17:14:08 Call stack: 17:14:08 00: 0x0000489f Source::Player::deleteJoint() 17:14:08 01: 0x0000db54 Source::Game::eventMouseSelect() 17:14:08 02: 0x00009965 Source::GameGlobal::eventMousePress() 17:14:08 Disassemble: 17:14:08 0x000048a1: callcd 17:14:08 0x000048a2: pushc string: "deleteJoint/n" 17:14:08 0x000048a4: callef log.message 17:14:08 0x000048a6: pop 17:14:08 0x000048a7: pushc int: 0 If I use next creation variant: joint = new JointFixed(innerBodyDummy, body, object.getPosition()); I have error too, but: 17:16:10 ExternClass::run_function(): object is NULL17:16:10 Stack dump: 17:16:10 0x0000: Source::Game 00000000042C7900 (1245199:0:0) 17:16:10 0x0001: vec4: 1.4013e-045 -1.#QNAN -1.#QNAN -1.#QNAN 17:16:10 Call stack: 17:16:10 00: 0x0000db52 Source::Game::eventMouseSelect() 17:16:10 01: 0x00009963 Source::GameGlobal::eventMousePress() 17:16:10 Disassemble: 17:16:10 0x0000db7e: callecf Object.getBodyRigid 17:16:10 0x0000db81: popv body 17:16:10 0x0000db83: pushv character 17:16:10 0x0000db85: pushucv Player.player How could I delete programmly created Joint? Thanks Link to comment
ulf.schroeter Posted February 12, 2011 Share Posted February 12, 2011 joint = class_remove(new JointFixed(innerBodyDummy, body, object.getPosition())); Then I need to delete this joint, I do next: delete joint; And get error: By calling class_remove you remove the object from the script environment, so you can't delete it from there afterwards. See documentation for class_remove in 'Programming\Core Sript Library\Common Functionality\System Functions' If I use next creation variant: joint = new JointFixed(innerBodyDummy, body, object.getPosition()); I have error too, but: Based on disassembly callecf Object.getBodyRigid the object node reference on which you call getBodyRigid() might be NULL. Do you check for non-null reference ? Posting complete initialization and de-initiaization code would be helpful. Link to comment
eugene.litvinov Posted February 12, 2011 Author Share Posted February 12, 2011 I use this (class_remove) cause I see it in examples (samples/joints/ball_00.cpp): void create_joint_default(Body b0,Body b1) { JointBall j = class_remove(new JointBall(b0,b1)); j.setLinearRestitution(0.8f); j.setAngularRestitution(0.8f); j.setLinearSoftness(0.0f); j.setAngularSoftness(0.0f); j.setAngularDamping(16.0f); j.setNumIterations(16); joints.append(j); } In manual I read: class_remove() releases the ownership of the pointer. After that, it becomes orphaned and should be handled by another module, for example, the Engine Editor. In examples joints only add in joints array, and not delete when shutdown() called. Maybe I need break joint before delete it? Link to comment
eugene.litvinov Posted February 12, 2011 Author Share Posted February 12, 2011 I initialize joint next code: JointFixed joint; ObjectDummy innerObjectDummy; void createJoint(Object object) { if (joint != NULL) return; log.message("createJoint/n"); vec3 p0 = player.getPosition() + vec3(0, 0, height + 0.3); vec3 p1 = player.getViewDirection(); vec3 p2 = p0 + p1 * snatchSize; innerObjectDummy = new ObjectDummy(); BodyDummy innerBodyDummy = class_remove(new BodyDummy(innerObjectDummy)); mat4 transform = translate(0, 0, height + 0.3) * rotate(0, 1, 0, player.getThetaAngle()); innerObjectDummy.setTransform(transform); player.addChild(innerObjectDummy); BodyRigid body = object.getBodyRigid(); Shape shape = body.getShape(0); jointObjectRestitution = shape.getRestitution(); shape.setRestitution(0.001); joint = new JointFixed(innerBodyDummy, body, object.getPosition()); joint.setBrokenCallback("Source::Player::eventJointBroken", this); joint.setMaxForce(4000.0f); joint.setMaxTorque(4000.0f); joint.setLinearRestitution(0.4f); joint.setAngularRestitution(0.4f); joint.setLinearSoftness(0.8f); joint.setAngularSoftness(0.8f); joint.setNumIterations(8); } In this function I pass object that created in editor and placed in world file. This object exists, cause creationJoint don't throw error. Next function called if joint is broken: void eventJointBroken(Joint joint, Player player) { BodyRigid body = joint.getBodyRigid1(); Shape shape = body.getShape(0); shape.setRestitution(player.jointObjectRestitution); player.deleteJoint(); } Next function cause errors: void deleteJoint() { if (joint != NULL) { player.removeChild(innerObjectDummy); delete joint; delete innerObjectDummy; } } Link to comment
frustum Posted February 12, 2011 Share Posted February 12, 2011 Bodies should have ownership on own joints and shapes. Because bodies deletes own joints and shapes in destructor. In same way all Object has ownership on bodies. To create joint or shape for body you always should call class_remove() function: Shape shape = class_remove(new ShapeSphere(body,1.0f)); All joints or shapes can be disabled if you don't need them. In case when you should delete joint or shape you should do following sequence of code: Joint joint = body.getJoint(num); body.removeJoint(joint); delete class_append(joint); Link to comment
eugene.litvinov Posted February 12, 2011 Author Share Posted February 12, 2011 All joints or shapes can be disabled if you don't need them. So I can do next: // create innerObjectDummy = new ObjectDummy(); BodyDummy innerBodyDummy = class_remove(new BodyDummy(innerObjectDummy)); player.addChild(innerObjectDummy); joint = class_remove(new JointFixed(innerBodyDummy, body, object.getPosition())); ... // delete player.removeChild(innerObjectDummy); joint.setEnabled(false); joint = NULL; delete innerObjectDummy; It's variant work. It's correct, If I will be only disable created joints? And next time I will be create new joint, and old joint will be deleted by garbage collector? I need joints to "take object in hand", so user can do this operation many times with many different objects. Link to comment
frustum Posted February 12, 2011 Share Posted February 12, 2011 When you delete an object, Object will delete own body and Body will delete own shapes and joints. Link to comment
eugene.litvinov Posted February 12, 2011 Author Share Posted February 12, 2011 I see, but I don't delete objects - I only "take" some object (create join) - user move it, and throw it in another place - I delete joint, but object must stay in new place. I use joint for allow user to carry physical objects from one place to another. Link to comment
Recommended Posts