Files
GDevelop/Core/GDCore/Project/Behavior.h
Florian Rival deba07f103 Add "MemoryTracked" classes and "UseAfterFreeError" (#8359)
- This will track alive/dead instances of some C++ classes and will throw a JS error in case of usage of a already destroyed object from JavaScript. This should avoid crashing/corrupting the wasm/C++ side by calling a method on an object already destroyed. Instead the exception stays on JS side, without reaching the C++ implementation.

Only show in developer changelog
2026-03-09 14:52:56 +01:00

60 lines
1.8 KiB
C++

/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#pragma once
#include "GDCore/String.h"
#include "GDCore/Project/BehaviorConfigurationContainer.h"
#include "GDCore/Project/MemoryTrackedRegistry.h"
#include "GDCore/Tools/MakeUnique.h"
namespace gd {
/**
* \brief Base class used to represents a behavior that can be applied to an
* object. It stores the content (i.e: the properties) of a behavior of an object
* and forward the properties related functions to Javascript with Emscripten.
*
* \see gd::BehaviorsSharedData
* \see gd::Object
* \ingroup PlatformDefinition
*/
class GD_CORE_API Behavior: public BehaviorConfigurationContainer {
public:
Behavior(): BehaviorConfigurationContainer(), isDefaultBehavior(false) {};
Behavior(const gd::String& name_, const gd::String& type_)
: BehaviorConfigurationContainer(name_, type_),
isDefaultBehavior(false) {};
Behavior(const Behavior& other)
: BehaviorConfigurationContainer(other),
isDefaultBehavior(other.isDefaultBehavior) {};
Behavior& operator=(const Behavior& other) {
if (this != &other) {
BehaviorConfigurationContainer::operator=(other);
isDefaultBehavior = other.isDefaultBehavior;
}
return *this;
}
virtual ~Behavior();
virtual std::unique_ptr<gd::Behavior> Clone() const {
return gd::make_unique<gd::Behavior>(*this);
}
bool IsDefaultBehavior() const {
return isDefaultBehavior;
}
void SetDefaultBehavior(bool isDefaultBehavior_) {
isDefaultBehavior = isDefaultBehavior_;
}
private:
gd::MemoryTracked _memoryTracked{this, "Behavior"};
bool isDefaultBehavior;
};
} // namespace gd