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);
|
result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
|
||||||
Log.i("calling Runtime.terminate()");
|
Log.i("calling Runtime.terminate()");
|
||||||
// commented out to fix hanging runtime.terminate when there are background threads
|
// commented out to fix hanging runtime.terminate when there are background threads
|
||||||
//Runtime.terminate();
|
Runtime.terminate();
|
||||||
}
|
}
|
||||||
catch (Throwable e) // catch any uncaught exceptions
|
catch (Throwable e) // catch any uncaught exceptions
|
||||||
{
|
{
|
||||||
|
|
|
@ -255,6 +255,46 @@ enum TextFlag : uint {
|
||||||
StrikeThrough = 16 // TODO:
|
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
|
/// style properties
|
||||||
class Style {
|
class Style {
|
||||||
protected:
|
protected:
|
||||||
|
@ -291,7 +331,7 @@ protected:
|
||||||
Style[] _substates;
|
Style[] _substates;
|
||||||
Style[] _children;
|
Style[] _children;
|
||||||
|
|
||||||
DrawableAttribute[string] _customDrawables;
|
DrawableAttributeList _customDrawables;
|
||||||
uint[string] _customColors;
|
uint[string] _customColors;
|
||||||
uint[string] _customLength;
|
uint[string] _customLength;
|
||||||
|
|
||||||
|
@ -305,9 +345,7 @@ public:
|
||||||
s.onThemeChanged();
|
s.onThemeChanged();
|
||||||
foreach(s; _children)
|
foreach(s; _children)
|
||||||
s.onThemeChanged();
|
s.onThemeChanged();
|
||||||
foreach(d; _customDrawables)
|
_customDrawables.clear();
|
||||||
d.clear();
|
|
||||||
destroy(_customDrawables);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@property const(Theme) theme() const {
|
@property const(Theme) theme() const {
|
||||||
|
@ -374,24 +412,21 @@ public:
|
||||||
|
|
||||||
/// get custom drawable attribute
|
/// get custom drawable attribute
|
||||||
ref DrawableRef customDrawable(string id) const {
|
ref DrawableRef customDrawable(string id) const {
|
||||||
if (id in _customDrawables)
|
if (_customDrawables.hasKey(id))
|
||||||
return _customDrawables[id].drawable;
|
return _customDrawables.drawable(id);
|
||||||
return parentStyle ? parentStyle.customDrawable(id) : currentTheme.customDrawable(id);
|
return parentStyle ? parentStyle.customDrawable(id) : currentTheme.customDrawable(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get custom drawable attribute
|
/// get custom drawable attribute
|
||||||
string customDrawableId(string id) const {
|
string customDrawableId(string id) const {
|
||||||
if (id in _customDrawables)
|
if (_customDrawables.hasKey(id))
|
||||||
return _customDrawables[id].drawableId;
|
return _customDrawables.drawableId(id);
|
||||||
return parentStyle ? parentStyle.customDrawableId(id) : currentTheme.customDrawableId(id);
|
return parentStyle ? parentStyle.customDrawableId(id) : currentTheme.customDrawableId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// sets custom drawable attribute for style
|
/// sets custom drawable attribute for style
|
||||||
Style setCustomDrawable(string id, string resourceId) {
|
Style setCustomDrawable(string id, string resourceId) {
|
||||||
if (id in _customDrawables)
|
_customDrawables.set(id, resourceId);
|
||||||
_customDrawables[id].drawableId = resourceId;
|
|
||||||
else
|
|
||||||
_customDrawables[id] = new DrawableAttribute(id, resourceId);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -794,6 +829,7 @@ public:
|
||||||
_children.destroy();
|
_children.destroy();
|
||||||
_backgroundDrawable.clear();
|
_backgroundDrawable.clear();
|
||||||
_font.clear();
|
_font.clear();
|
||||||
|
destroy(_customDrawables);
|
||||||
debug _instanceCount--;
|
debug _instanceCount--;
|
||||||
//Log.d("Destroyed style ", _id, ", parentId=", _parentId, ", state=", _stateMask, ", count=", --_instanceCount);
|
//Log.d("Destroyed style ", _id, ", parentId=", _parentId, ", state=", _stateMask, ", count=", --_instanceCount);
|
||||||
}
|
}
|
||||||
|
@ -849,7 +885,7 @@ public:
|
||||||
|
|
||||||
res._focusRectColors = _focusRectColors.dup;
|
res._focusRectColors = _focusRectColors.dup;
|
||||||
|
|
||||||
res._customDrawables = _customDrawables.dup;
|
res._customDrawables.copyFrom(_customDrawables);
|
||||||
res._customColors = _customColors.dup;
|
res._customColors = _customColors.dup;
|
||||||
res._customLength = _customLength.dup;
|
res._customLength = _customLength.dup;
|
||||||
return res;
|
return res;
|
||||||
|
@ -977,14 +1013,14 @@ class Theme : Style {
|
||||||
|
|
||||||
private DrawableRef _emptyDrawable;
|
private DrawableRef _emptyDrawable;
|
||||||
override ref DrawableRef customDrawable(string id) const {
|
override ref DrawableRef customDrawable(string id) const {
|
||||||
if (id in _customDrawables)
|
if (_customDrawables.hasKey(id))
|
||||||
return _customDrawables[id].drawable;
|
return _customDrawables.drawable(id);
|
||||||
return (cast(Theme)this)._emptyDrawable;
|
return (cast(Theme)this)._emptyDrawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
override string customDrawableId(string id) const {
|
override string customDrawableId(string id) const {
|
||||||
if (id in _customDrawables)
|
if (_customDrawables.hasKey(id))
|
||||||
return _customDrawables[id].drawableId;
|
_customDrawables.drawableId(id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1599,6 +1635,9 @@ public:
|
||||||
_id = id;
|
_id = id;
|
||||||
_drawableId = drawableId;
|
_drawableId = drawableId;
|
||||||
}
|
}
|
||||||
|
~this() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
@property string id() const { return _id; }
|
@property string id() const { return _id; }
|
||||||
@property string drawableId() const { return _drawableId; }
|
@property string drawableId() const { return _drawableId; }
|
||||||
@property void drawableId(string newDrawable) { _drawableId = newDrawable; clear(); }
|
@property void drawableId(string newDrawable) { _drawableId = newDrawable; clear(); }
|
||||||
|
|
Loading…
Reference in New Issue