mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-28 16:43:29 +00:00
fix memory errors realted to cache
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
WARNING: SHADER: [ID 5] Failed to find shader attribute: vertexTexCoord2
|
||||
WARNING: SHADER: [ID 5] Failed to find shader attribute: vertexNormal
|
||||
WARNING: SHADER: [ID 5] Failed to find shader attribute: vertexTangent
|
||||
WARNING: SHADER: [ID 5] Failed to find shader attribute: vertexColor
|
||||
WARNING: SHADER: [ID 5] Failed to find shader uniform: view
|
||||
WARNING: SHADER: [ID 5] Failed to find shader uniform: projection
|
||||
WARNING: SHADER: [ID 5] Failed to find shader uniform: matNormal
|
||||
WARNING: SHADER: [ID 5] Failed to find shader uniform: colDiffuse
|
||||
WARNING: SHADER: [ID 5] Failed to find shader uniform: texture1
|
||||
WARNING: SHADER: [ID 5] Failed to find shader uniform: texture2
|
||||
@@ -0,0 +1,44 @@
|
||||
==6548== Memcheck, a memory error detector
|
||||
==6548== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
|
||||
==6548== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
|
||||
==6548== Command: ./build/bomberman
|
||||
==6548==
|
||||
==6548== Conditional jump or move depends on uninitialised value(s)
|
||||
==6548== at 0x541752: RAY::ModelAnimations::ModelAnimations(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x4FD08E: BBM::Runner::createPlayer(WAL::Scene&) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x4C9EF6: BBM::LobbySystem::switchToGame(WAL::Wal&) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x51918A: BBM::Runner::loadLobbyScene()::{lambda(WAL::Entity&, WAL::Wal&)#3}::operator()(WAL::Entity&, WAL::Wal&) const (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x520084: void std::__invoke_impl<void, BBM::Runner::loadLobbyScene()::{lambda(WAL::Entity&, WAL::Wal&)#3}&, WAL::Entity&, WAL::Wal&>(std::__invoke_other, BBM::Runner::loadLobbyScene()::{lambda(WAL::Entity&, WAL::Wal&)#3}&, WAL::Entity&, WAL::Wal&) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x51F0A0: std::enable_if<is_invocable_r_v<void, BBM::Runner::loadLobbyScene()::{lambda(WAL::Entity&, WAL::Wal&)#3}&, WAL::Entity&, WAL::Wal&>, std::enable_if>::type std::__invoke_r<void, BBM::Runner::loadLobbyScene()::{lambda(WAL::Entity&, WAL::Wal&)#3}&, WAL::Entity&, WAL::Wal&>(void&&, (BBM::Runner::loadLobbyScene()::{lambda(WAL::Entity&, WAL::Wal&)#3}&)...) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x51E27A: std::_Function_handler<void (WAL::Entity&, WAL::Wal&), BBM::Runner::loadLobbyScene()::{lambda(WAL::Entity&, WAL::Wal&)#3}>::_M_invoke(std::_Any_data const&, WAL::Entity&, WAL::Wal&) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x4515E6: std::function<void (WAL::Entity&, WAL::Wal&)>::operator()(WAL::Entity&, WAL::Wal&) const (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x451481: WAL::Callback<WAL::Entity&, WAL::Wal&>::operator()(WAL::Entity&, WAL::Wal&) const (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x49A22D: BBM::MenuControllableSystem::_updateCurrentButton(bool, BBM::Vector2<float>) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x49A401: BBM::MenuControllableSystem::onFixedUpdate(WAL::ViewEntity<BBM::ControllableComponent>&) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x49F7A7: WAL::System<BBM::ControllableComponent>::fixedUpdate() (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548==
|
||||
==6548==
|
||||
==6548== Process terminating with default action of signal 1 (SIGHUP)
|
||||
==6548== at 0x494951: WAL::ViewIterator<__gnu_cxx::__normal_iterator<std::tuple<std::reference_wrapper<WAL::Entity>, std::reference_wrapper<BBM::PositionComponent>, std::reference_wrapper<BBM::CollisionComponent> >*, std::vector<std::tuple<std::reference_wrapper<WAL::Entity>, std::reference_wrapper<BBM::PositionComponent>, std::reference_wrapper<BBM::CollisionComponent> >, std::allocator<std::tuple<std::reference_wrapper<WAL::Entity>, std::reference_wrapper<BBM::PositionComponent>, std::reference_wrapper<BBM::CollisionComponent> > > > >, BBM::PositionComponent, BBM::CollisionComponent>::operator++() (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x4944A2: BBM::CollisionSystem::onFixedUpdate(WAL::ViewEntity<BBM::PositionComponent, BBM::CollisionComponent>&) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x49937B: WAL::System<BBM::PositionComponent, BBM::CollisionComponent>::fixedUpdate() (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x41154E: void WAL::Wal::_run<BBM::GameState>(WAL::Callback<WAL::Wal&, BBM::GameState&> const&, BBM::GameState) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x40DA60: void WAL::Wal::run<BBM::GameState>(WAL::Callback<WAL::Wal&, BBM::GameState&> const&, BBM::GameState) (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x40871B: BBM::Runner::run() (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548== by 0x406F15: main (in /home/arthurjamet/Desktop/B4/YEP/Bomberman/build/bomberman)
|
||||
==6548==
|
||||
==6548== HEAP SUMMARY:
|
||||
==6548== in use at exit: 85,100,138 bytes in 63,937 blocks
|
||||
==6548== total heap usage: 200,879 allocs, 136,942 frees, 426,519,550 bytes allocated
|
||||
==6548==
|
||||
==6548== LEAK SUMMARY:
|
||||
==6548== definitely lost: 408 bytes in 1 blocks
|
||||
==6548== indirectly lost: 0 bytes in 0 blocks
|
||||
==6548== possibly lost: 6,687,735 bytes in 41,704 blocks
|
||||
==6548== still reachable: 78,411,995 bytes in 22,232 blocks
|
||||
==6548== suppressed: 0 bytes in 0 blocks
|
||||
==6548== Rerun with --leak-check=full to see details of leaked memory
|
||||
==6548==
|
||||
==6548== Use --track-origins=yes to see where uninitialised values come from
|
||||
==6548== For lists of detected and suppressed errors, rerun with: -s
|
||||
==6548== ERROR SUMMARY: 4383708 errors from 1 contexts (suppressed: 0 from 0)
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <iostream>
|
||||
#include "Model/ModelAnimation.hpp"
|
||||
|
||||
RAY::ModelAnimation::ModelAnimation(::ModelAnimation *animation):
|
||||
RAY::ModelAnimation::ModelAnimation(::ModelAnimation animation):
|
||||
_animation(animation), _frameCounter(0)
|
||||
{
|
||||
}
|
||||
@@ -20,26 +20,23 @@ size_t RAY::ModelAnimation::getFrameCounter() const
|
||||
|
||||
size_t RAY::ModelAnimation::getFrameCount() const
|
||||
{
|
||||
return this->_animation->frameCount;
|
||||
return this->_animation.frameCount;
|
||||
}
|
||||
|
||||
RAY::ModelAnimation &RAY::ModelAnimation::setFrameCounter(size_t frameCounter)
|
||||
{
|
||||
std::cout << this << std::endl;
|
||||
std::cout << this->_animation << std::endl;
|
||||
std::cout << this->_animation->frameCount << std::endl;
|
||||
this->_frameCounter = frameCounter % this->_animation->frameCount;
|
||||
this->_frameCounter = frameCounter % this->_animation.frameCount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RAY::ModelAnimation &RAY::ModelAnimation::incrementFrameCounter()
|
||||
{
|
||||
this->_frameCounter = (this->_frameCounter + 1) % this->_animation->frameCount;
|
||||
this->_frameCounter = (this->_frameCounter + 1) % this->_animation.frameCount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
RAY::ModelAnimation::operator ::ModelAnimation() const
|
||||
{
|
||||
return *this->_animation;
|
||||
return this->_animation;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace RAY {
|
||||
public:
|
||||
//! @brief A Model animation constructor
|
||||
//! @param animationPtr an animation pointer, returned by the nimation-loading function
|
||||
explicit ModelAnimation(::ModelAnimation *animationPtr);
|
||||
explicit ModelAnimation(::ModelAnimation animation);
|
||||
|
||||
//! @brief A default copy-constructor
|
||||
ModelAnimation(const ModelAnimation &) = default;
|
||||
@@ -41,7 +41,7 @@ namespace RAY {
|
||||
~ModelAnimation() = default;
|
||||
|
||||
private:
|
||||
::ModelAnimation *_animation;
|
||||
::ModelAnimation _animation;
|
||||
|
||||
size_t _frameCounter;
|
||||
INTERNAL:
|
||||
|
||||
@@ -16,7 +16,7 @@ RAY::ModelAnimations::ModelAnimations(const std::string &filePath):
|
||||
::ModelAnimation *ptr = this->_animationsPtr.get();
|
||||
|
||||
for (int i = 0; i < this->_animationCount; i++)
|
||||
this->_animations.emplace_back(ptr + i);
|
||||
this->_animations.emplace_back(ptr[i]);
|
||||
}
|
||||
|
||||
RAY::ModelAnimation &RAY::ModelAnimations::operator[](int index)
|
||||
|
||||
@@ -73,24 +73,6 @@ namespace RAY {
|
||||
|
||||
template<>
|
||||
class Cache<::ModelAnimation> {
|
||||
public:
|
||||
Cache(std::function<::ModelAnimation *(const char *, int *)> dataLoader, std::function<void(::ModelAnimation *, unsigned int)>dataUnloader):
|
||||
_dataLoader(std::move(dataLoader)), _dataUnloader(std::move(dataUnloader))
|
||||
{};
|
||||
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
|
||||
{
|
||||
if (this->_cache.find(path) != this->_cache.end())
|
||||
return this->_cache[path];
|
||||
|
||||
::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter);
|
||||
unsigned int animCount = *counter;
|
||||
|
||||
this->_cache.emplace(path, std::shared_ptr<::ModelAnimation>(
|
||||
animations, [this, animCount](::ModelAnimation *p) {
|
||||
this->_dataUnloader(p, animCount);
|
||||
}));
|
||||
return this->_cache[path];
|
||||
};
|
||||
private:
|
||||
//! @brief function to call to load data
|
||||
std::function<::ModelAnimation *(const char *, int *)> _dataLoader;
|
||||
@@ -98,10 +80,34 @@ namespace RAY {
|
||||
//! @brief function to call when the ray data will be unloaded
|
||||
std::function<void(::ModelAnimation *, unsigned int)> _dataUnloader;
|
||||
|
||||
//! @brief map storing shared ptr of caches
|
||||
std::unordered_map<std::string, std::shared_ptr<::ModelAnimation>> _cache;
|
||||
};
|
||||
typedef struct {
|
||||
std::shared_ptr<::ModelAnimation> animations;
|
||||
int animationsCount;
|
||||
} AnimationsHolder;
|
||||
|
||||
//! @brief map storing shared ptr of caches
|
||||
std::unordered_map<std::string, AnimationsHolder> _cache;
|
||||
public:
|
||||
Cache(std::function<::ModelAnimation *(const char *, int *)> dataLoader, std::function<void(::ModelAnimation *, unsigned int)>dataUnloader):
|
||||
_dataLoader(std::move(dataLoader)), _dataUnloader(std::move(dataUnloader))
|
||||
{};
|
||||
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
|
||||
{
|
||||
if (this->_cache.find(path) != this->_cache.end()) {
|
||||
*counter = this->_cache[path].animationsCount;
|
||||
} else {
|
||||
::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter);
|
||||
int animCount = *counter;
|
||||
|
||||
this->_cache.emplace(path, (AnimationsHolder){
|
||||
std::shared_ptr<::ModelAnimation>(
|
||||
animations, [this, animCount](::ModelAnimation *p) {
|
||||
this->_dataUnloader(p, animCount);
|
||||
}), animCount});
|
||||
}
|
||||
return this->_cache[path].animations;
|
||||
};
|
||||
};
|
||||
template<>
|
||||
class Cache<::Shader>
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play)
|
||||
AnimationsComponent::AnimationsComponent(WAL::Entity &entity, const std::string &path, int animIndex, bool play)
|
||||
: WAL::Component(entity),
|
||||
_modelAnimation(std::move(modelAnimation)),
|
||||
_modelAnimation(path),
|
||||
_currentAnimIndex(animIndex),
|
||||
_animDisabled(play)
|
||||
{
|
||||
@@ -20,7 +20,7 @@ namespace BBM
|
||||
WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new AnimationsComponent(entity,
|
||||
RAY::ModelAnimations(this->_modelAnimation.getFilePath()),
|
||||
this->_modelAnimation.getFilePath(),
|
||||
this->_currentAnimIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace BBM
|
||||
bool isAnimDisabled() const;
|
||||
|
||||
//! @brief ctor entity and the path of the animation file
|
||||
explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play = true);
|
||||
explicit AnimationsComponent(WAL::Entity &entity, const std::string &path, int animIndex, bool play = true);
|
||||
//! @brief copy ctor
|
||||
AnimationsComponent(const AnimationsComponent &) = default;
|
||||
//! @brief dtor
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace BBM
|
||||
.addComponent<AnimatorComponent>()
|
||||
// .addComponent<ShaderComponentModel>("assets/shaders/glsl330/predator.fs")
|
||||
.addComponent<TagComponent<Blowable>>()
|
||||
// .addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
|
||||
.addComponent<AnimationsComponent>("assets/player/player.iqm", 3)
|
||||
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<SoundComponent>(soundPath)
|
||||
|
||||
Reference in New Issue
Block a user