investigating memory error in runtime shutdown

This commit is contained in:
Vadim Lopatin 2014-04-30 09:09:02 +04:00
parent 078d5832d3
commit 233adaace3
4 changed files with 41 additions and 4 deletions

View File

@ -479,6 +479,8 @@ class Window {
class Platform { class Platform {
static __gshared Platform _instance; static __gshared Platform _instance;
static void setInstance(Platform instance) { static void setInstance(Platform instance) {
if (_instance)
destroy(_instance);
_instance = instance; _instance = instance;
} }
@property static Platform instance() { @property static Platform instance() {

View File

@ -17,6 +17,7 @@ version(USE_SDL) {
import dlangui.graphics.ftfonts; import dlangui.graphics.ftfonts;
import dlangui.graphics.resources; import dlangui.graphics.resources;
import dlangui.widgets.styles; import dlangui.widgets.styles;
import dlangui.widgets.widget;
import dlangui.platforms.common.platform; import dlangui.platforms.common.platform;
import derelict.sdl2.sdl; import derelict.sdl2.sdl;
@ -123,6 +124,7 @@ version(USE_SDL) {
} }
void redraw() { void redraw() {
Log.e("Widget instance count in SDLWindow.redraw: ", Widget.instanceCount());
// check if size has been changed // check if size has been changed
int w, h; int w, h;
SDL_GetWindowSize(_win, SDL_GetWindowSize(_win,
@ -748,16 +750,25 @@ version(USE_SDL) {
int res = 0; int res = 0;
res = UIAppMain(args); res = UIAppMain(args);
//Log.e("Widget instance count after UIAppMain: ", Widget.instanceCount());
Platform.setInstance(null);
Log.d("Destroying SDL platform"); Log.d("Destroying SDL platform");
destroy(sdl); Platform.setInstance(null);
//
debug {
Widget.shuttingDown();
}
currentTheme = null; currentTheme = null;
drawableCache = null; drawableCache = null;
imageCache = null; imageCache = null;
FontManager.instance = null; FontManager.instance = null;
debug {
if (Widget.instanceCount() > 0) {
Log.e("Non-zero Widget instance count when exiting: ", Widget.instanceCount());
}
}
Log.d("Exiting main"); Log.d("Exiting main");
return res; return res;

View File

@ -62,6 +62,9 @@ class WidgetListAdapter : ListAdapter {
override uint resetItemState(int index, uint flags) { override uint resetItemState(int index, uint flags) {
return _widgets.get(index).resetState(flags).state; return _widgets.get(index).resetState(flags).state;
} }
~this() {
//Log.d("Destroying WidgetListAdapter");
}
} }
/// List /// List
@ -348,6 +351,7 @@ class ListWidget : WidgetGroup, OnScrollHandler {
} }
~this() { ~this() {
//Log.d("Destroying List ", _id);
if (_adapter !is null && _ownAdapter) if (_adapter !is null && _ownAdapter)
destroy(_adapter); destroy(_adapter);
_adapter = null; _adapter = null;

View File

@ -121,19 +121,39 @@ class Widget {
/// set new trackHover flag value (when true, widget will change Hover state while mouse is moving) /// 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; } @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 /// create widget, with optional id
this(string ID = null) { this(string ID = null) {
_id = ID; _id = ID;
_state = State.Enabled; _state = State.Enabled;
debug {
_instanceCount++;
}
//Log.d("Created widget, count = ", ++_instanceCount); //Log.d("Created widget, count = ", ++_instanceCount);
} }
~this() { ~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) if (_ownStyle !is null)
destroy(_ownStyle); destroy(_ownStyle);
_ownStyle = null; _ownStyle = null;
//Log.d("Destroyed widget, count = ", --_instanceCount); //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). /// 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 { protected @property const (Style) style() const {