mirror of https://github.com/buggins/dlangui.git
investigating memory error in runtime shutdown
This commit is contained in:
parent
078d5832d3
commit
233adaace3
|
@ -479,6 +479,8 @@ class Window {
|
|||
class Platform {
|
||||
static __gshared Platform _instance;
|
||||
static void setInstance(Platform instance) {
|
||||
if (_instance)
|
||||
destroy(_instance);
|
||||
_instance = instance;
|
||||
}
|
||||
@property static Platform instance() {
|
||||
|
|
|
@ -17,6 +17,7 @@ version(USE_SDL) {
|
|||
import dlangui.graphics.ftfonts;
|
||||
import dlangui.graphics.resources;
|
||||
import dlangui.widgets.styles;
|
||||
import dlangui.widgets.widget;
|
||||
import dlangui.platforms.common.platform;
|
||||
|
||||
import derelict.sdl2.sdl;
|
||||
|
@ -123,6 +124,7 @@ version(USE_SDL) {
|
|||
}
|
||||
|
||||
void redraw() {
|
||||
Log.e("Widget instance count in SDLWindow.redraw: ", Widget.instanceCount());
|
||||
// check if size has been changed
|
||||
int w, h;
|
||||
SDL_GetWindowSize(_win,
|
||||
|
@ -748,16 +750,25 @@ version(USE_SDL) {
|
|||
int res = 0;
|
||||
|
||||
res = UIAppMain(args);
|
||||
//Log.e("Widget instance count after UIAppMain: ", Widget.instanceCount());
|
||||
|
||||
Platform.setInstance(null);
|
||||
Log.d("Destroying SDL platform");
|
||||
destroy(sdl);
|
||||
Platform.setInstance(null);
|
||||
|
||||
//
|
||||
debug {
|
||||
Widget.shuttingDown();
|
||||
}
|
||||
|
||||
currentTheme = null;
|
||||
drawableCache = null;
|
||||
imageCache = null;
|
||||
FontManager.instance = null;
|
||||
|
||||
debug {
|
||||
if (Widget.instanceCount() > 0) {
|
||||
Log.e("Non-zero Widget instance count when exiting: ", Widget.instanceCount());
|
||||
}
|
||||
}
|
||||
Log.d("Exiting main");
|
||||
|
||||
return res;
|
||||
|
|
|
@ -62,6 +62,9 @@ class WidgetListAdapter : ListAdapter {
|
|||
override uint resetItemState(int index, uint flags) {
|
||||
return _widgets.get(index).resetState(flags).state;
|
||||
}
|
||||
~this() {
|
||||
//Log.d("Destroying WidgetListAdapter");
|
||||
}
|
||||
}
|
||||
|
||||
/// List
|
||||
|
@ -348,6 +351,7 @@ class ListWidget : WidgetGroup, OnScrollHandler {
|
|||
}
|
||||
|
||||
~this() {
|
||||
//Log.d("Destroying List ", _id);
|
||||
if (_adapter !is null && _ownAdapter)
|
||||
destroy(_adapter);
|
||||
_adapter = null;
|
||||
|
|
|
@ -121,19 +121,39 @@ class Widget {
|
|||
/// set new trackHover flag value (when true, widget will change Hover state while mouse is moving)
|
||||
@property Widget trackHover(bool v) { _trackHover = v; return this; }
|
||||
|
||||
//private static int _instanceCount = 0;
|
||||
debug {
|
||||
private static int _instanceCount = 0;
|
||||
private static bool _appShuttingDown = false;
|
||||
}
|
||||
/// create widget, with optional id
|
||||
this(string ID = null) {
|
||||
_id = ID;
|
||||
_state = State.Enabled;
|
||||
debug {
|
||||
_instanceCount++;
|
||||
}
|
||||
//Log.d("Created widget, count = ", ++_instanceCount);
|
||||
}
|
||||
~this() {
|
||||
debug {
|
||||
//Log.v("destroying widget ", _id);
|
||||
if (_appShuttingDown)
|
||||
Log.e("Destroying widget ", _id, " after app shutdown: probably, resource leak");
|
||||
_instanceCount--;
|
||||
}
|
||||
if (_ownStyle !is null)
|
||||
destroy(_ownStyle);
|
||||
_ownStyle = null;
|
||||
//Log.d("Destroyed widget, count = ", --_instanceCount);
|
||||
}
|
||||
debug {
|
||||
/// for debug purposes - number of created widget objects, not yet destroyed
|
||||
static @property int instanceCount() { return _instanceCount; }
|
||||
/// for debug purposes - sets shutdown flag to log widgets not destroyed in time.
|
||||
static void shuttingDown() {
|
||||
_appShuttingDown = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// accessor to style - by lookup in theme by styleId (if style id is not set, theme base style will be used).
|
||||
protected @property const (Style) style() const {
|
||||
|
|
Loading…
Reference in New Issue