overte/libraries/render-utils/src/AnimDebugDraw.h
Anthony Thibault dc43d1bf8f AnimDebugDraw: Prevent multi-threaded access to shared map collection.
It was possible for the render thread to iterate over a map while the main thread mutates the same map.
This could have led to memory corruption and crashes.

To fix this we make a copy of the collection and pass the copy to the lambda that executes on the render thread.
2018-11-02 17:53:07 -07:00

55 lines
1.4 KiB
C++

//
// AnimDebugDraw.h
//
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_AnimDebugDraw_h
#define hifi_AnimDebugDraw_h
#include <tuple>
#include <gpu/Pipeline.h>
#include <render/Scene.h>
#include "AnimNode.h"
#include "AnimSkeleton.h"
class AnimDebugDrawData;
typedef render::Payload<AnimDebugDrawData> AnimDebugDrawPayload;
class AnimDebugDraw {
public:
static AnimDebugDraw& getInstance();
AnimDebugDraw();
~AnimDebugDraw();
void shutdown();
void addAbsolutePoses(const std::string& key, AnimSkeleton::ConstPointer skeleton, const AnimPoseVec& poses, const AnimPose& rootPose, const glm::vec4& color);
void removeAbsolutePoses(const std::string& key);
void update();
protected:
std::shared_ptr<AnimDebugDrawData> _animDebugDrawData;
std::shared_ptr<AnimDebugDrawPayload> _animDebugDrawPayload;
render::ItemID _itemID{ render::Item::INVALID_ITEM_ID };
static gpu::PipelinePointer _pipeline;
typedef std::tuple<AnimSkeleton::ConstPointer, AnimPoseVec, AnimPose, glm::vec4> PosesInfo;
typedef std::unordered_map<std::string, PosesInfo> PosesInfoMap;
PosesInfoMap _posesInfoMap;
// no copies
AnimDebugDraw(const AnimDebugDraw&) = delete;
AnimDebugDraw& operator=(const AnimDebugDraw&) = delete;
};
#endif // hifi_AnimDebugDraw