mirror of https://github.com/buggins/dlangui.git
fix crash on exit - resource cleanup - issue #302
This commit is contained in:
parent
e2bc56d976
commit
10d27af9c2
|
@ -1666,7 +1666,7 @@ version (Windows) {
|
|||
result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
|
||||
Log.i("calling Runtime.terminate()");
|
||||
// commented out to fix hanging runtime.terminate when there are background threads
|
||||
//Runtime.terminate();
|
||||
Runtime.terminate();
|
||||
}
|
||||
catch (Throwable e) // catch any uncaught exceptions
|
||||
{
|
||||
|
|
|
@ -255,6 +255,46 @@ enum TextFlag : uint {
|
|||
StrikeThrough = 16 // TODO:
|
||||
}
|
||||
|
||||
struct DrawableAttributeList {
|
||||
DrawableAttribute[string] _customDrawables;
|
||||
~this() {
|
||||
clear();
|
||||
}
|
||||
void clear() {
|
||||
foreach(key, ref value; _customDrawables) {
|
||||
if (value) {
|
||||
destroy(value);
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
destroy(_customDrawables);
|
||||
_customDrawables = null;
|
||||
}
|
||||
bool hasKey(string key) const {
|
||||
return (key in _customDrawables) !is null;
|
||||
}
|
||||
ref DrawableRef drawable(string id) const {
|
||||
return _customDrawables[id].drawable;
|
||||
}
|
||||
/// get custom drawable attribute
|
||||
string drawableId(string id) const {
|
||||
return _customDrawables[id].drawableId;
|
||||
}
|
||||
void set(string id, string resourceId) {
|
||||
if (id in _customDrawables) {
|
||||
_customDrawables[id].drawableId = resourceId;
|
||||
} else {
|
||||
_customDrawables[id] = new DrawableAttribute(id, resourceId);
|
||||
}
|
||||
}
|
||||
void copyFrom(ref DrawableAttributeList v) {
|
||||
clear();
|
||||
foreach(key, value; v._customDrawables) {
|
||||
set(key, value.drawableId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// style properties
|
||||
class Style {
|
||||
protected:
|
||||
|
@ -291,7 +331,7 @@ protected:
|
|||
Style[] _substates;
|
||||
Style[] _children;
|
||||
|
||||
DrawableAttribute[string] _customDrawables;
|
||||
DrawableAttributeList _customDrawables;
|
||||
uint[string] _customColors;
|
||||
uint[string] _customLength;
|
||||
|
||||
|
@ -305,9 +345,7 @@ public:
|
|||
s.onThemeChanged();
|
||||
foreach(s; _children)
|
||||
s.onThemeChanged();
|
||||
foreach(d; _customDrawables)
|
||||
d.clear();
|
||||
destroy(_customDrawables);
|
||||
_customDrawables.clear();
|
||||
}
|
||||
|
||||
@property const(Theme) theme() const {
|
||||
|
@ -374,24 +412,21 @@ public:
|
|||
|
||||
/// get custom drawable attribute
|
||||
ref DrawableRef customDrawable(string id) const {
|
||||
if (id in _customDrawables)
|
||||
return _customDrawables[id].drawable;
|
||||
if (_customDrawables.hasKey(id))
|
||||
return _customDrawables.drawable(id);
|
||||
return parentStyle ? parentStyle.customDrawable(id) : currentTheme.customDrawable(id);
|
||||
}
|
||||
|
||||
/// get custom drawable attribute
|
||||
string customDrawableId(string id) const {
|
||||
if (id in _customDrawables)
|
||||
return _customDrawables[id].drawableId;
|
||||
if (_customDrawables.hasKey(id))
|
||||
return _customDrawables.drawableId(id);
|
||||
return parentStyle ? parentStyle.customDrawableId(id) : currentTheme.customDrawableId(id);
|
||||
}
|
||||
|
||||
/// sets custom drawable attribute for style
|
||||
Style setCustomDrawable(string id, string resourceId) {
|
||||
if (id in _customDrawables)
|
||||
_customDrawables[id].drawableId = resourceId;
|
||||
else
|
||||
_customDrawables[id] = new DrawableAttribute(id, resourceId);
|
||||
_customDrawables.set(id, resourceId);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -794,6 +829,7 @@ public:
|
|||
_children.destroy();
|
||||
_backgroundDrawable.clear();
|
||||
_font.clear();
|
||||
destroy(_customDrawables);
|
||||
debug _instanceCount--;
|
||||
//Log.d("Destroyed style ", _id, ", parentId=", _parentId, ", state=", _stateMask, ", count=", --_instanceCount);
|
||||
}
|
||||
|
@ -849,7 +885,7 @@ public:
|
|||
|
||||
res._focusRectColors = _focusRectColors.dup;
|
||||
|
||||
res._customDrawables = _customDrawables.dup;
|
||||
res._customDrawables.copyFrom(_customDrawables);
|
||||
res._customColors = _customColors.dup;
|
||||
res._customLength = _customLength.dup;
|
||||
return res;
|
||||
|
@ -977,14 +1013,14 @@ class Theme : Style {
|
|||
|
||||
private DrawableRef _emptyDrawable;
|
||||
override ref DrawableRef customDrawable(string id) const {
|
||||
if (id in _customDrawables)
|
||||
return _customDrawables[id].drawable;
|
||||
if (_customDrawables.hasKey(id))
|
||||
return _customDrawables.drawable(id);
|
||||
return (cast(Theme)this)._emptyDrawable;
|
||||
}
|
||||
|
||||
override string customDrawableId(string id) const {
|
||||
if (id in _customDrawables)
|
||||
return _customDrawables[id].drawableId;
|
||||
if (_customDrawables.hasKey(id))
|
||||
_customDrawables.drawableId(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1599,6 +1635,9 @@ public:
|
|||
_id = id;
|
||||
_drawableId = drawableId;
|
||||
}
|
||||
~this() {
|
||||
clear();
|
||||
}
|
||||
@property string id() const { return _id; }
|
||||
@property string drawableId() const { return _drawableId; }
|
||||
@property void drawableId(string newDrawable) { _drawableId = newDrawable; clear(); }
|
||||
|
|
Loading…
Reference in New Issue