Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leak checkers; and clean up offscreen caches #1651

Merged
merged 1 commit into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/common/gui/CScalableBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "nanosvg.h"

using namespace VSTGUI;
std::atomic<int> CScalableBitmap::instances( 0 );

#if MAC
static const std::string svgFullFileNameFromBundle(const std::string& filename)
Expand Down Expand Up @@ -99,6 +100,10 @@ CScalableBitmap::CScalableBitmap(CResourceDescription desc, VSTGUI::CFrame* f)
if(desc.type == CResourceDescription::kIntegerType)
id = (int32_t)desc.u.id;

instances++;
//std::cout << " Construct CScalableBitmap. instances=" << instances << " id=" << id << std::endl;


resourceID = id;

std::stringstream filename;
Expand Down Expand Up @@ -167,9 +172,14 @@ CScalableBitmap::CScalableBitmap(CResourceDescription desc, VSTGUI::CFrame* f)
lastSeenZoom = -1;
}

CScalableBitmap::CScalableBitmap(std::string fname, VSTGUI::CFrame* f)
CScalableBitmap::CScalableBitmap(std::string ifname, VSTGUI::CFrame* f)
: CBitmap(CResourceDescription(0)), svgImage(nullptr), frame(f)
{
fname = ifname;

instances++;
//std::cout << " Construct CScalableBitmap. instances=" << instances << " fname=" << fname << std::endl;

int id = 0;
resourceID = id;

Expand All @@ -185,6 +195,21 @@ CScalableBitmap::CScalableBitmap(std::string fname, VSTGUI::CFrame* f)
lastSeenZoom = -1;
}

CScalableBitmap::~CScalableBitmap()
{
for (auto const& pair : offscreenCache)
{
auto val = pair.second;
if (val)
val->forget();
}
offscreenCache.clear();

instances--;
//std::cout << " Destroy CScalableBitmap. instances=" << instances << " id=" << resourceID << " fn=" << fname << std::endl;
}


#define DUMPR(r) \
"(x=" << r.getTopLeft().x << ",y=" << r.getTopLeft().y << ")+(w=" << r.getWidth() \
<< ",h=" << r.getHeight() << ")"
Expand Down
6 changes: 5 additions & 1 deletion src/common/gui/CScalableBitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <vector>
#include <map>
#include <atomic>

#include "nanosvg.h"

Expand All @@ -17,6 +18,7 @@ class CScalableBitmap : public VSTGUI::CBitmap
public:
CScalableBitmap(VSTGUI::CResourceDescription d, VSTGUI::CFrame* f);
CScalableBitmap(std::string fname, VSTGUI::CFrame* f);
~CScalableBitmap();

virtual void draw(VSTGUI::CDrawContext* context,
const VSTGUI::CRect& rect,
Expand Down Expand Up @@ -60,10 +62,12 @@ class CScalableBitmap : public VSTGUI::CBitmap
};

std::map<VSTGUI::CPoint, VSTGUI::CBitmap*, CPointCompare> offscreenCache;

static std::atomic<int> instances;

int lastSeenZoom, bestFitScaleGroup;
int extraScaleFactor;
int resourceID;
std::string fname;

VSTGUI::CFrame* frame;

Expand Down
8 changes: 6 additions & 2 deletions src/common/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,19 @@ std::unordered_map<std::string, int> createIdNameMap()
return res;
}

std::atomic<int> Skin::instances( 0 );

Skin::Skin(std::string root, std::string name) : root(root), name(name)
{
std::cout << "Constructing a skin " << _D(root) << _D(name) << std::endl;
instances++;
std::cout << "Constructing a skin " << _D(root) << _D(name) << _D(instances) << std::endl;
imageIds = createIdNameMap();
}

Skin::~Skin()
{
std::cout << "Destroying a skin" << std::endl;
instances--;
std::cout << "Destroying a skin " << _D(instances) << std::endl;
}

#if !defined(TINYXML_SAFE_TO_ELEMENT)
Expand Down
2 changes: 2 additions & 0 deletions src/common/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <atomic>

#include "vstgui/lib/ccolor.h"

Expand Down Expand Up @@ -82,6 +83,7 @@ class Skin
std::unordered_set<std::string> getQueriedColors() { return queried_colors; }

private:
static std::atomic<int> instances;
std::vector<std::pair<std::string, props_t>> globals;

std::unordered_map<std::string, VSTGUI::CColor> colors;
Expand Down
7 changes: 7 additions & 0 deletions src/common/gui/SurgeBitmaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

using namespace VSTGUI;

std::atomic<int> SurgeBitmaps::instances( 0 );
SurgeBitmaps::SurgeBitmaps()
{
instances++;
std::cout << "Constructing a SurgeBitmaps; Instances is " << instances << std::endl;
}

SurgeBitmaps::~SurgeBitmaps()
Expand All @@ -25,6 +28,10 @@ SurgeBitmaps::~SurgeBitmaps()
pair.second->forget();
}
bitmap_registry.clear();
bitmap_file_registry.clear();
bitmap_stringid_registry.clear();
instances --;
std::cout << "Destroying a SurgeBitmaps; Instances is " << instances << std::endl;
}

void SurgeBitmaps::setupBitmapsForFrame(VSTGUI::CFrame* f)
Expand Down
3 changes: 3 additions & 0 deletions src/common/gui/SurgeBitmaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "resource.h"
#include "vstgui/vstgui.h"
#include <map>
#include <atomic>

class CScalableBitmap;

Expand All @@ -24,6 +25,8 @@ class SurgeBitmaps
CScalableBitmap* loadBitmapByPathForStringID(std::string filename, std::string id);

protected:
static std::atomic<int> instances;

void addEntry(int id, VSTGUI::CFrame* f);
std::map<int, CScalableBitmap*> bitmap_registry;
std::map<std::string, CScalableBitmap*> bitmap_file_registry;
Expand Down