mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 10:22:52 +01:00
rwengine: make AnimationBone a shared pointer
Should fix this memory leak: ==10780== 4,341,444 (269,712 direct, 4,071,732 indirect) bytes in 3,746 blocks are definitely lost in los s record 2,652 of 2,654 ==10780== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334) ==10780== by 0x8219B2: LoaderIFP::loadFromMemory(char*) (LoaderIFP.cpp:82) ==10780== by 0x7C22C0: GameData::loadIFP(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameData.cpp:506) ==10780== by 0x7BD838: GameData::load() (GameData.cpp:59) ==10780== by 0x75CD35: RWGame::RWGame(Logger&, int, char**) (RWGame.cpp:51) ==10780== by 0x74CDE5: main (main.cpp:13) ==10780== ==10780== 6,516,576 (13,968 direct, 6,502,608 indirect) bytes in 194 blocks are definitely lost in loss record 2,654 of 2,654 ==10780== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334) ==10780== by 0x8219B2: LoaderIFP::loadFromMemory(char*) (LoaderIFP.cpp:82) ==10780== by 0x7C22C0: GameData::loadIFP(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameData.cpp:506) ==10780== by 0x7E7ECC: GameWorld::loadCutscene(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameWorld.cpp:693) ==10780== by 0x87453E: opcode_02e4(ScriptArguments const&, char const*) (GTA3ModuleImpl.inl:8245) ==10780== by 0x8D8149: void script_bind::call_unpacked<0u, 2u, void>::call<void (*)(ScriptArguments const&, char const*), ScriptArguments const&, char const*>(void (*)(ScriptArguments const&, char const*), ScriptArguments const&, ScriptArguments const&, char const*&&) (ScriptModule.hpp:80) ==10780== by 0x8D2765: void script_bind::call_unpacked<1u, 1u, void, char const*>::call<void (*)(ScriptArguments const&, char const*), ScriptArguments const&>(void (*)(ScriptArguments const&, char const*), ScriptArguments const&, ScriptArguments const&) (ScriptModule.hpp:90) ==10780== by 0x8C7EFE: void script_bind::call_unpacked<2u, 0u, void, ScriptArguments const&, char const*>::call<void (*)(ScriptArguments const&, char const*)>(void (*)(ScriptArguments const&, char const*), ScriptArguments const&) (ScriptModule.hpp:90) ==10780== by 0x8B5A05: void script_bind::binder<void, ScriptArguments const&, char const*>::call<void (*)(ScriptArguments const&, char const*)>(void (*)(ScriptArguments const&, char const*), ScriptArguments const&) (ScriptModule.hpp:104) ==10780== by 0x8A2E3A: void script_bind::do_unpacked_call<void, ScriptArguments const&, char const*>(void (* const&)(ScriptArguments const&, char const*), ScriptArguments const&) (ScriptModule.hpp:137) ==10780== by 0x893BB0: void ScriptModule::bind<void (*)(ScriptArguments const&, char const*)>(unsigned short, int, void (*)(ScriptArguments const&, char const*))::{lambda(ScriptArguments const&)#1}::operator()(ScriptArguments const&) const (ScriptModule.hpp:166) ==10780== by 0x8B5A8D: std::_Function_handler<void (ScriptArguments const&), void ScriptModule::bind<void (*)(ScriptArguments const&, char const*)>(unsigned short, int, void (*)(ScriptArguments const&, char const*))::{lambda(ScriptArguments const&)#1}>::_M_invoke(std::_Any_data const&, ScriptArguments const&) (std_function.h:316)
This commit is contained in:
parent
5e330346ec
commit
8175666092
@ -34,7 +34,7 @@ class Animator {
|
||||
float speed;
|
||||
/// Automatically restart
|
||||
bool repeat;
|
||||
std::map<AnimationBone*, ModelFrame*> boneInstances;
|
||||
std::map<std::shared_ptr<AnimationBone>, ModelFrame*> boneInstances;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -79,7 +79,7 @@ bool LoaderIFP::loadFromMemory(char* data) {
|
||||
CPAN* cpan = read<CPAN>(data, dataI);
|
||||
ANIM* frames = read<ANIM>(data, dataI);
|
||||
|
||||
AnimationBone* bonedata = new AnimationBone;
|
||||
auto bonedata = std::make_shared<AnimationBone>();
|
||||
bonedata->name = frames->name;
|
||||
bonedata->frames.reserve(frames->frames);
|
||||
|
||||
|
@ -40,7 +40,7 @@ struct AnimationBone {
|
||||
*/
|
||||
struct Animation {
|
||||
std::string name;
|
||||
std::map<std::string, AnimationBone*> bones;
|
||||
std::map<std::string, std::shared_ptr<AnimationBone>> bones;
|
||||
|
||||
float duration;
|
||||
};
|
||||
|
@ -198,7 +198,7 @@ glm::vec3 CharacterObject::updateMovementAnimation(float dt) {
|
||||
const auto& root = modelroot->getChildren()[0];
|
||||
auto it = movementAnimation->bones.find(root->getName());
|
||||
if (it != movementAnimation->bones.end()) {
|
||||
AnimationBone* rootBone = it->second;
|
||||
auto rootBone = it->second;
|
||||
float step = dt;
|
||||
const float duration =
|
||||
animator->getAnimation(AnimIndexMovement)->duration;
|
||||
|
@ -18,7 +18,8 @@ BOOST_AUTO_TEST_CASE(test_matrix) {
|
||||
Animator animator(test_model);
|
||||
|
||||
animation->duration = 1.f;
|
||||
animation->bones["player"] = new AnimationBone{
|
||||
animation->bones["player"] = std::shared_ptr<AnimationBone>(
|
||||
new AnimationBone {
|
||||
"player",
|
||||
0,
|
||||
0,
|
||||
@ -27,7 +28,9 @@ BOOST_AUTO_TEST_CASE(test_matrix) {
|
||||
{
|
||||
{glm::quat(), glm::vec3(0.f, 0.f, 0.f), glm::vec3(), 0.f, 0},
|
||||
{glm::quat(), glm::vec3(0.f, 1.f, 0.f), glm::vec3(), 1.0f, 1},
|
||||
}};
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
animator.playAnimation(0, animation, 1.f, false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user