Skip to content

segfault in destructor when destroying PhysicsCommon's default logger #443

@robinwils

Description

@robinwils

this simple sample code taken from the docs leads to segfault:

#include <reactphysics3d/reactphysics3d.h>

using namespace reactphysics3d;

int main(void) {
  PhysicsCommon physicsCommon;

  // Create a physics world
  PhysicsWorld *world = physicsCommon.createPhysicsWorld();
  // Create the default logger
  DefaultLogger *logger = physicsCommon.createDefaultLogger();

  // Log level (warnings and errors)
  uint logLevel = static_cast<uint>(static_cast<uint>(Logger::Level::Warning) |
                                    static_cast<uint>(Logger::Level::Error));

  // Output the logs into an HTML file
  logger->addFileDestination("rp3d_log.html", logLevel,
                             DefaultLogger::Format::HTML);

  // Output the logs into the standard output
  logger->addStreamDestination(std::cout, logLevel,
                               DefaultLogger::Format::Text);

  // Set the logger
  physicsCommon.setLogger(logger);
  physicsCommon.destroyDefaultLogger(logger);
  return 0;
}

segfaults on log here because the static PhysicsCommon logger is not set to null after destruction.

Calling physicsCommon.setLogger(nullptr); after destroying the default logger prevents that.

Maybe there should be a check in destroyDefaultLogger or deleteDefaultLogger on the logger being deleted. If it is the current PhysicsCommon logger, set to nullptr ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions