Rick Posted November 13, 2013 Share Posted November 13, 2013 Normally the access violation happens when we try to call a method of a pointer that's not pointing to anything. Below I get this on SetGravityMode() of the pivot. The pivot variable is valid as SetMass() works. What am I missing? RTSCamera::RTSCamera(void) { shape = Shape::Sphere(0, 0, 0, 1, 1, 1, 0, 0, 0); pivot = Pivot::Create(); pivot->SetShape(shape); shape->AddRef(); pivot->SetMass(1); pivot->SetGravityMode(false); /// gives me access violation } Quote Link to comment Share on other sites More sharing options...
tjheldna Posted November 13, 2013 Share Posted November 13, 2013 Hey Rick, This works for me, I think the problem might be in your shape constructor as I think size is the 7th, 8th, 9th param so your box doesn't have a size. Shape *shape = Shape::Box(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.4F, 0.4F, 0.4F); Pivot *pivot = Pivot::Create(); pivot->SetShape(shape); shape->Release(); pivot->SetPhysicsMode(Entity::RigidBodyPhysics); pivot->SetMass(10.0F); Quote Link to comment Share on other sites More sharing options...
Josh Posted November 13, 2013 Share Posted November 13, 2013 FYI, you don't need to increment the shape ref count. It will automatically do that when you add it to the shape. Your normal usage shuld be like this: shape = Shape::Sphere(); pivot = Pivot::Create(); pivot->SetShape(shape); shape->Release(); 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted November 13, 2013 Author Share Posted November 13, 2013 I still get access violation with the below code. TJ I'm using a Sphere not a Box as in your example. I removed the params as the default does have a size but I get the same error. shape = Shape::Sphere(); pivot = Pivot::Create(); pivot->SetShape(shape); shape->Release(); pivot->SetPhysicsMode(Entity::RigidBodyPhysics); pivot->SetMass(1); pivot->SetGravityMode(false); // access violation Quote Link to comment Share on other sites More sharing options...
Rick Posted November 13, 2013 Author Share Posted November 13, 2013 So I'm trying to get a RTS style camera where W always move forward, S moves backwards, etc but the camera is angled pointing down. I can't get the camera to move though. <man can we get the code formatting fixed for these forums > header #pragma once #include "Leadwerks.h" using namespace Leadwerks; class RTSCamera { private: Pivot* pivot; Shape* shape; public: RTSCamera(void); ~RTSCamera(void); void StartingPosition(Camera& camera); void Update(Window& window, Camera& camera); }; source #include "RTSCamera.h" RTSCamera::RTSCamera(void) { shape = Shape::Sphere(); pivot = Pivot::Create(); pivot->SetShape(shape); shape->Release(); pivot->SetPhysicsMode(Entity::RigidBodyPhysics); pivot->SetMass(1); //pivot->SetGravityMode(false); } RTSCamera::~RTSCamera(void) { shape->Release(); pivot->Release(); pivot = NULL; shape = NULL; } void RTSCamera::StartingPosition(Camera& camera) { pivot->SetPosition(camera.GetPosition(true), true); } void RTSCamera::Update(Window& window, Camera& camera) { Vec3 velocity = Vec3(); Vec3 currentVelocity = pivot->GetVelocity(); Vec3 finalVelocity = Vec3(); if(window.KeyDown(Key::W)) velocity.z++; velocity *= 20; velocity = Transform::Vector(velocity, &camera, NULL); finalVelocity = (velocity - currentVelocity) * 60; if(finalVelocity.Length() > 0) pivot->AddForce(velocity); camera.SetPosition(pivot->GetPosition(true), true); } Quote Link to comment Share on other sites More sharing options...
Rick Posted November 13, 2013 Author Share Posted November 13, 2013 Nevermind, this was all being created before LE was initialized. All good now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.