summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouis <louis.braun@gmx.de>2015-04-06 09:58:33 +0200
committerlouis <louis.braun@gmx.de>2015-04-06 09:58:33 +0200
commitd70bfe70913602de016e14d17d4ac485a8683cf5 (patch)
treeee00aff7748877323d71ac75d97924ced3029395
parentf316b2628aa63a7d37c9a76ad147fc6e04e14fa3 (diff)
downloadvdr-plugin-skindesigner-d70bfe70913602de016e14d17d4ac485a8683cf5.tar.gz
vdr-plugin-skindesigner-d70bfe70913602de016e14d17d4ac485a8683cf5.tar.bz2
added locks around cTextWrappers to avoid crashed when concurrently accessing fonts
-rw-r--r--HISTORY3
-rw-r--r--libcore/helpers.c2
-rw-r--r--libtemplate/templatefunction.c10
-rw-r--r--views/view.c11
4 files changed, 25 insertions, 1 deletions
diff --git a/HISTORY b/HISTORY
index b6cb8e8..fd7e173 100644
--- a/HISTORY
+++ b/HISTORY
@@ -280,3 +280,6 @@ Version 0.4.0
Version 0.4.1
+- added locks around cTextWrappers to avoid crashed when concurrently
+ accessing fonts
+
diff --git a/libcore/helpers.c b/libcore/helpers.c
index 5dc5156..9604e3a 100644
--- a/libcore/helpers.c
+++ b/libcore/helpers.c
@@ -51,8 +51,10 @@ int Minimum(int a, int b, int c, int d, int e, int f) {
string CutText(string &text, int width, string fontName, int fontSize) {
if (width <= fontManager->Font(fontName, fontSize)->Size())
return text.c_str();
+ fontManager->Lock();
cTextWrapper twText;
twText.Set(text.c_str(), fontManager->Font(fontName, fontSize), width);
+ fontManager->Unlock();
string cuttedTextNative = twText.GetLine(0);
stringstream sstrText;
sstrText << cuttedTextNative << "...";
diff --git a/libtemplate/templatefunction.c b/libtemplate/templatefunction.c
index 6aa1ddd..2e6a743 100644
--- a/libtemplate/templatefunction.c
+++ b/libtemplate/templatefunction.c
@@ -1331,8 +1331,10 @@ int cTemplateFunction::CalculateTextBoxHeight(void) {
int floatType = GetNumericParameter(ptFloat);
if (floatType == flNone) {
+ fontManager->Lock();
cTextWrapper wrapper;
wrapper.Set(text.c_str(), font, width);
+ fontManager->Unlock();
int lines = wrapper.Lines();
return (lines * fontHeight);
}
@@ -1370,7 +1372,9 @@ int cTemplateFunction::CalculateTextBoxHeight(void) {
} else {
cTextWrapper wrapper;
if (drawNarrow) {
+ fontManager->Lock();
wrapper.Set((flds[i].c_str()), font, widthNarrow);
+ fontManager->Unlock();
int newLines = wrapper.Lines();
//check if wrapper fits completely into narrow area
if (linesDrawn + newLines < linesNarrow) {
@@ -1392,7 +1396,9 @@ int cTemplateFunction::CalculateTextBoxHeight(void) {
drawNarrow = false;
}
} else {
+ fontManager->Lock();
wrapper.Set((flds[i].c_str()), font, width);
+ fontManager->Unlock();
for (int line = 0; line < wrapper.Lines(); line++) {
sstrTextFull << wrapper.GetLine(line) << " ";
}
@@ -1400,8 +1406,12 @@ int cTemplateFunction::CalculateTextBoxHeight(void) {
}
}
}
+ fontManager->Lock();
wTextTall.Set(sstrTextTall.str().c_str(), font, widthNarrow);
+ fontManager->Unlock();
+ fontManager->Lock();
wTextFull.Set(sstrTextFull.str().c_str(), font, width);
+ fontManager->Unlock();
int textLinesTall = wTextTall.Lines();
int textLinesFull = wTextFull.Lines();
diff --git a/views/view.c b/views/view.c
index 3d7f369..8ee8c09 100644
--- a/views/view.c
+++ b/views/view.c
@@ -576,8 +576,10 @@ void cView::DoDrawTextBox(int num, cTemplateFunction *func, int x0, int y0) {
const cFont *font = fontManager->Font(fontName, fontSize);
if (!font)
return;
+ fontManager->Lock();
cTextWrapper wrapper;
wrapper.Set(text.c_str(), font, width);
+ fontManager->Unlock();
int fontHeight = fontManager->Height(fontName, fontSize);
int lines = wrapper.Lines();
int yLine = y;
@@ -659,7 +661,9 @@ void cView::DoDrawFloatingTextBox(int num, cTemplateFunction *func) {
} else {
cTextWrapper wrapper;
if (drawNarrow) {
+ fontManager->Lock();
wrapper.Set((flds[i].c_str()), font, widthNarrow);
+ fontManager->Unlock();
int newLines = wrapper.Lines();
//check if wrapper fits completely into narrow area
if (linesDrawn + newLines < linesNarrow) {
@@ -681,7 +685,9 @@ void cView::DoDrawFloatingTextBox(int num, cTemplateFunction *func) {
drawNarrow = false;
}
} else {
+ fontManager->Lock();
wrapper.Set((flds[i].c_str()), font, width);
+ fontManager->Unlock();
for (int line = 0; line < wrapper.Lines(); line++) {
sstrTextFull << wrapper.GetLine(line) << " ";
}
@@ -697,9 +703,12 @@ void cView::DoDrawFloatingTextBox(int num, cTemplateFunction *func) {
if (posLastCarriageReturn != string::npos && (posLastCarriageReturn < textTall.size() - 1)) {
numLinesToAddAtTall = textTall.size() - posLastCarriageReturn - 2;
}
-
+ fontManager->Lock();
wTextTall.Set(textTall.c_str(), font, widthNarrow);
+ fontManager->Unlock();
+ fontManager->Lock();
wTextFull.Set(sstrTextFull.str().c_str(), font, width);
+ fontManager->Unlock();
int textLinesTall = wTextTall.Lines();
int textLinesFull = wTextFull.Lines();