jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6k stars 374 forks source link

Declare Job destructor as virtual. #1101

Closed dm-tesla closed 2 months ago

dm-tesla commented 2 months ago

This is needed to prevent leaks from user-derived jobs. For example:

class JobImpl: final Job {
    const std::string internal_string;
};

In this case, the internal_string will not be automatically freed.

CLAassistant commented 2 months ago

CLA assistant check
All committers have signed the CLA.

jrouwe commented 2 months ago

Hello,

The Job class doesn't have any virtual functions on purpose. There's only 1 way it can be destroyed: JobSystem::FreeJob so you can free it like:

void MyJobSystem::FreeJob(Job *inJob)
{
    delete static_cast<JobImpl *>(inJob);
}
dm-tesla commented 2 months ago

I see, thank you for the answer! Closing the issue. I wish there was a way to guard against that properly. Seeing all those leaks wasn't expected.