mirror of
https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
synced 2023-10-19 17:58:31 +02:00
added locks around cTextWrappers to avoid crashed when concurrently accessing fonts
This commit is contained in:
parent
f316b2628a
commit
d70bfe7091
3
HISTORY
3
HISTORY
@ -280,3 +280,6 @@ Version 0.4.0
|
|||||||
|
|
||||||
Version 0.4.1
|
Version 0.4.1
|
||||||
|
|
||||||
|
- added locks around cTextWrappers to avoid crashed when concurrently
|
||||||
|
accessing fonts
|
||||||
|
|
||||||
|
@ -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) {
|
string CutText(string &text, int width, string fontName, int fontSize) {
|
||||||
if (width <= fontManager->Font(fontName, fontSize)->Size())
|
if (width <= fontManager->Font(fontName, fontSize)->Size())
|
||||||
return text.c_str();
|
return text.c_str();
|
||||||
|
fontManager->Lock();
|
||||||
cTextWrapper twText;
|
cTextWrapper twText;
|
||||||
twText.Set(text.c_str(), fontManager->Font(fontName, fontSize), width);
|
twText.Set(text.c_str(), fontManager->Font(fontName, fontSize), width);
|
||||||
|
fontManager->Unlock();
|
||||||
string cuttedTextNative = twText.GetLine(0);
|
string cuttedTextNative = twText.GetLine(0);
|
||||||
stringstream sstrText;
|
stringstream sstrText;
|
||||||
sstrText << cuttedTextNative << "...";
|
sstrText << cuttedTextNative << "...";
|
||||||
|
@ -1331,8 +1331,10 @@ int cTemplateFunction::CalculateTextBoxHeight(void) {
|
|||||||
int floatType = GetNumericParameter(ptFloat);
|
int floatType = GetNumericParameter(ptFloat);
|
||||||
|
|
||||||
if (floatType == flNone) {
|
if (floatType == flNone) {
|
||||||
|
fontManager->Lock();
|
||||||
cTextWrapper wrapper;
|
cTextWrapper wrapper;
|
||||||
wrapper.Set(text.c_str(), font, width);
|
wrapper.Set(text.c_str(), font, width);
|
||||||
|
fontManager->Unlock();
|
||||||
int lines = wrapper.Lines();
|
int lines = wrapper.Lines();
|
||||||
return (lines * fontHeight);
|
return (lines * fontHeight);
|
||||||
}
|
}
|
||||||
@ -1370,7 +1372,9 @@ int cTemplateFunction::CalculateTextBoxHeight(void) {
|
|||||||
} else {
|
} else {
|
||||||
cTextWrapper wrapper;
|
cTextWrapper wrapper;
|
||||||
if (drawNarrow) {
|
if (drawNarrow) {
|
||||||
|
fontManager->Lock();
|
||||||
wrapper.Set((flds[i].c_str()), font, widthNarrow);
|
wrapper.Set((flds[i].c_str()), font, widthNarrow);
|
||||||
|
fontManager->Unlock();
|
||||||
int newLines = wrapper.Lines();
|
int newLines = wrapper.Lines();
|
||||||
//check if wrapper fits completely into narrow area
|
//check if wrapper fits completely into narrow area
|
||||||
if (linesDrawn + newLines < linesNarrow) {
|
if (linesDrawn + newLines < linesNarrow) {
|
||||||
@ -1392,7 +1396,9 @@ int cTemplateFunction::CalculateTextBoxHeight(void) {
|
|||||||
drawNarrow = false;
|
drawNarrow = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
fontManager->Lock();
|
||||||
wrapper.Set((flds[i].c_str()), font, width);
|
wrapper.Set((flds[i].c_str()), font, width);
|
||||||
|
fontManager->Unlock();
|
||||||
for (int line = 0; line < wrapper.Lines(); line++) {
|
for (int line = 0; line < wrapper.Lines(); line++) {
|
||||||
sstrTextFull << wrapper.GetLine(line) << " ";
|
sstrTextFull << wrapper.GetLine(line) << " ";
|
||||||
}
|
}
|
||||||
@ -1400,8 +1406,12 @@ int cTemplateFunction::CalculateTextBoxHeight(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fontManager->Lock();
|
||||||
wTextTall.Set(sstrTextTall.str().c_str(), font, widthNarrow);
|
wTextTall.Set(sstrTextTall.str().c_str(), font, widthNarrow);
|
||||||
|
fontManager->Unlock();
|
||||||
|
fontManager->Lock();
|
||||||
wTextFull.Set(sstrTextFull.str().c_str(), font, width);
|
wTextFull.Set(sstrTextFull.str().c_str(), font, width);
|
||||||
|
fontManager->Unlock();
|
||||||
|
|
||||||
int textLinesTall = wTextTall.Lines();
|
int textLinesTall = wTextTall.Lines();
|
||||||
int textLinesFull = wTextFull.Lines();
|
int textLinesFull = wTextFull.Lines();
|
||||||
|
11
views/view.c
11
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);
|
const cFont *font = fontManager->Font(fontName, fontSize);
|
||||||
if (!font)
|
if (!font)
|
||||||
return;
|
return;
|
||||||
|
fontManager->Lock();
|
||||||
cTextWrapper wrapper;
|
cTextWrapper wrapper;
|
||||||
wrapper.Set(text.c_str(), font, width);
|
wrapper.Set(text.c_str(), font, width);
|
||||||
|
fontManager->Unlock();
|
||||||
int fontHeight = fontManager->Height(fontName, fontSize);
|
int fontHeight = fontManager->Height(fontName, fontSize);
|
||||||
int lines = wrapper.Lines();
|
int lines = wrapper.Lines();
|
||||||
int yLine = y;
|
int yLine = y;
|
||||||
@ -659,7 +661,9 @@ void cView::DoDrawFloatingTextBox(int num, cTemplateFunction *func) {
|
|||||||
} else {
|
} else {
|
||||||
cTextWrapper wrapper;
|
cTextWrapper wrapper;
|
||||||
if (drawNarrow) {
|
if (drawNarrow) {
|
||||||
|
fontManager->Lock();
|
||||||
wrapper.Set((flds[i].c_str()), font, widthNarrow);
|
wrapper.Set((flds[i].c_str()), font, widthNarrow);
|
||||||
|
fontManager->Unlock();
|
||||||
int newLines = wrapper.Lines();
|
int newLines = wrapper.Lines();
|
||||||
//check if wrapper fits completely into narrow area
|
//check if wrapper fits completely into narrow area
|
||||||
if (linesDrawn + newLines < linesNarrow) {
|
if (linesDrawn + newLines < linesNarrow) {
|
||||||
@ -681,7 +685,9 @@ void cView::DoDrawFloatingTextBox(int num, cTemplateFunction *func) {
|
|||||||
drawNarrow = false;
|
drawNarrow = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
fontManager->Lock();
|
||||||
wrapper.Set((flds[i].c_str()), font, width);
|
wrapper.Set((flds[i].c_str()), font, width);
|
||||||
|
fontManager->Unlock();
|
||||||
for (int line = 0; line < wrapper.Lines(); line++) {
|
for (int line = 0; line < wrapper.Lines(); line++) {
|
||||||
sstrTextFull << wrapper.GetLine(line) << " ";
|
sstrTextFull << wrapper.GetLine(line) << " ";
|
||||||
}
|
}
|
||||||
@ -697,9 +703,12 @@ void cView::DoDrawFloatingTextBox(int num, cTemplateFunction *func) {
|
|||||||
if (posLastCarriageReturn != string::npos && (posLastCarriageReturn < textTall.size() - 1)) {
|
if (posLastCarriageReturn != string::npos && (posLastCarriageReturn < textTall.size() - 1)) {
|
||||||
numLinesToAddAtTall = textTall.size() - posLastCarriageReturn - 2;
|
numLinesToAddAtTall = textTall.size() - posLastCarriageReturn - 2;
|
||||||
}
|
}
|
||||||
|
fontManager->Lock();
|
||||||
wTextTall.Set(textTall.c_str(), font, widthNarrow);
|
wTextTall.Set(textTall.c_str(), font, widthNarrow);
|
||||||
|
fontManager->Unlock();
|
||||||
|
fontManager->Lock();
|
||||||
wTextFull.Set(sstrTextFull.str().c_str(), font, width);
|
wTextFull.Set(sstrTextFull.str().c_str(), font, width);
|
||||||
|
fontManager->Unlock();
|
||||||
|
|
||||||
int textLinesTall = wTextTall.Lines();
|
int textLinesTall = wTextTall.Lines();
|
||||||
int textLinesFull = wTextFull.Lines();
|
int textLinesFull = wTextFull.Lines();
|
||||||
|
Loading…
Reference in New Issue
Block a user