Jump to content

Object::RemoveHook causing FEEEFEEE inside Object::Release


Recommended Posts

Hello,

 

example code to raise this exception:

 

#include "App.h"
using namespace Leadwerks;
Entity* entity = NULL;
void UpdateWorldHook(Leadwerks::Entity* entity);
void PostRenderHook(Leadwerks::Entity* entity);
void UpdatePhysicsHook(Leadwerks::Entity* entity);
void CollisionHook(Leadwerks::Entity* entity0, Leadwerks::Entity* entity1, float* position, float* normal, float speed);
App::App() : window(NULL), context(NULL), world(NULL), camera(NULL)
{
}
App::~App()
{
// Clear any set user data
entity->SetUserData(NULL);
// Remove hooks
entity->RemoveHook(Entity::UpdateWorldHook, &UpdateWorldHook);
entity->RemoveHook(Entity::UpdatePhysicsHook, &UpdatePhysicsHook);
entity->RemoveHook(Entity::PostRenderHook, &PostRenderHook);
entity->RemoveHook(Entity::CollisionHook, &CollisionHook);
entity->Release();
entity = NULL;
delete world; delete window;
}
Vec3 camerarotation;
#if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS)
bool freelookmode=true;
#else
bool freelookmode=false;
#endif
bool App::Start()
{
//Initialize Steamworks (optional)
/*if (!Steamworks::Initialize())
{
System::Print("Error: Failed to initialize Steam.");
return false;
}*/
//Create a window
window = Leadwerks::Window::Create("tst");

//Create a context
context = Context::Create(window);

//Create a world
world = World::Create();

//Create a camera
camera = Camera::Create();
camera->Move(0,2,-5);

//Hide the mouse cursor
window->HideMouse();

std::string mapname = System::GetProperty("map","Maps/start.map");
Map::Load(mapname);

//Move the mouse to the center of the screen
window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2);
entity = Pivot::Create();
entity->SetUserData(this);
// Register hooks
entity->AddHook(Entity::UpdateWorldHook, &UpdateWorldHook);
entity->AddHook(Entity::UpdatePhysicsHook, &UpdatePhysicsHook);
entity->AddHook(Entity::PostRenderHook, &PostRenderHook);
entity->AddHook(Entity::CollisionHook, &CollisionHook);

return true;
}
bool App::Loop()
{
//Close the window to end the program
if (window->Closed()) return false;

//Press escape to end freelook mode
if (window->KeyHit(Key::Escape))
{
if (!freelookmode) return false;
freelookmode=false;
window->ShowMouse();
}

if (freelookmode)
{
//Keyboard movement
float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Leadwerks::Time::GetSpeed() * 0.05;
float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Leadwerks::Time::GetSpeed() * 0.05;
camera->Move(strafe,0,move);
//Get the mouse movement
float sx = context->GetWidth()/2;
float sy = context->GetHeight()/2;
Vec3 mouseposition = window->GetMousePosition();
float dx = mouseposition.x - sx;
float dy = mouseposition.y - sy;
//Adjust and set the camera rotation
camerarotation.x += dy / 10.0;
camerarotation.y += dx / 10.0;
camera->SetRotation(camerarotation);
//Move the mouse to the center of the screen
window->SetMousePosition(sx,sy);
}
Leadwerks::Time::Update();
world->Update();
world->Render();
context->Sync(false);

return true;
}
void UpdateWorldHook(Leadwerks::Entity* entity)
{
}
void PostRenderHook(Leadwerks::Entity* entity)
{
}
void UpdatePhysicsHook(Leadwerks::Entity* entity)
{
}
void CollisionHook(Leadwerks::Entity* entity0, Leadwerks::Entity* entity1, float* position, float* normal, float speed)
{
}

 

Comment out the Object::RemoveHook calls to prevent this from happening.

Link to comment
Share on other sites

  • 2 months later...
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...