fix crash in release mode

This commit is contained in:
Vadim Lopatin 2015-11-11 14:56:25 +03:00
parent c125c224b8
commit 53c20f0498
7 changed files with 123 additions and 45 deletions

View File

@ -40,7 +40,7 @@
"configurations": [ "configurations": [
{ {
"name": "default", "name": "default",
"versions": ["USE_OPENGL", "EmbedStandardResources", "USE_FREETYPE"], "versions": ["USE_OPENGL", "EmbedStandardResources", "USE_FREETYPE", "ForceLogs"],
"versions-posix": ["USE_SDL"], "versions-posix": ["USE_SDL"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"dependencies": { "dependencies": {
@ -50,7 +50,7 @@
"gl3n": "~>1.2.0" "gl3n": "~>1.2.0"
}, },
"dependencies-posix": { "dependencies-posix": {
"derelict-sdl2": "~>1.9.1" "derelict-sdl2": "~>1.9.7"
}, },
"copyFiles-windows-x86_64": [ "copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll" "libs/windows/x86_64/libfreetype-6.dll"
@ -59,6 +59,19 @@
"libs/windows/x86/libfreetype-6.dll" "libs/windows/x86/libfreetype-6.dll"
] ]
}, },
{
"name": "minimal",
"versions": ["EmbedStandardResources", "ForceLogs"],
"versions-posix": ["USE_SDL", "USE_FREETYPE"],
"versions-windows": ["Unicode"],
"dependencies": {
"dlib": "~>0.7.0",
"gl3n": "~>1.2.0"
},
"dependencies-posix": {
"derelict-sdl2": "~>1.9.7"
}
},
{ {
"name": "sdl", "name": "sdl",
"versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"], "versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"],
@ -88,7 +101,7 @@
"derelict-gl3": "~>1.0.16", "derelict-gl3": "~>1.0.16",
"derelict-ft": "~>1.0.2", "derelict-ft": "~>1.0.2",
"gl3n": "~>1.2.0", "gl3n": "~>1.2.0",
"dsfml": "~master" "dsfml": "~>2.1.0"
}, },
"copyFiles-windows-x86_64": [ "copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll" "libs/windows/x86_64/libfreetype-6.dll"

View File

@ -9,11 +9,17 @@
"targetType": "executable", "targetType": "executable",
"targetName": "example1", "targetName": "example1",
"versions": ["EmbedStandardResources", "ForceLogs"],
"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi"], "stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi"],
"sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"], "sourceFiles-windows": ["$PACKAGE_DIR/src/win_app.def"],
"dependencies": { "dependencies": {
"dlangui": "*" "dlangui": {"path": "../../"}
},
"subConfigurations": {
"dlangui": "minimal"
} }
} }

View File

@ -189,8 +189,8 @@ enum : int {
extern (C) int UIAppMain(string[] args) { extern (C) int UIAppMain(string[] args) {
// always use trace, even for release builds // always use trace, even for release builds
Log.setLogLevel(LogLevel.Trace); //Log.setLogLevel(LogLevel.Trace);
Log.setFileLogger(std.stdio.File("ui.log", "w")); //Log.setFileLogger(new std.stdio.File("ui.log", "w"));
// resource directory search paths // resource directory search paths
// not required if only embedded resources are used // not required if only embedded resources are used

View File

@ -76,33 +76,56 @@ Log.e("exception while reading file", e);
---- ----
*/ */
synchronized class Log {
static: import core.sync.mutex;
__gshared private LogLevel logLevel = LogLevel.Info;
__gshared private std.stdio.File logFile; class Log {
static __gshared private LogLevel logLevel = LogLevel.Info;
static __gshared private std.stdio.File * logFile = null;
static __gshared private Mutex mutex = null;
static this() {
Log.mutex = new Mutex();
}
/// Redirects output to stdout /// Redirects output to stdout
void setStdoutLogger() { static public void setStdoutLogger() {
logFile = stdout; synchronized(mutex) {
logFile = &stdout;
}
} }
/// Redirects output to stderr /// Redirects output to stderr
void setStderrLogger() { static public void setStderrLogger() {
logFile = stderr; synchronized(mutex) {
logFile = &stderr;
}
} }
/// Redirects output to file /// Redirects output to file
void setFileLogger(File file) { static public void setFileLogger(File * file) {
logFile = file; synchronized(mutex) {
if (logFile !is null && logFile != &stdout && logFile != &stderr) {
logFile.close();
destroy(logFile);
logFile = null;
}
logFile = file;
if (logFile !is null)
logFile.writeln("DlangUI log file");
}
} }
/// Sets log level (one of LogLevel) /// Sets log level (one of LogLevel)
void setLogLevel(LogLevel level) { static public void setLogLevel(LogLevel level) {
logLevel = level; synchronized(mutex) {
logLevel = level;
i("Log level changed to ", level);
}
} }
/// Log level to name helper function /// Log level to name helper function
string logLevelName(LogLevel level) { static public string logLevelName(LogLevel level) {
switch (level) { switch (level) {
case LogLevel.Fatal: return "F"; case LogLevel.Fatal: return "F";
case LogLevel.Error: return "E"; case LogLevel.Error: return "E";
@ -114,8 +137,8 @@ synchronized class Log {
} }
} }
/// Log message with arbitrary log level /// Log message with arbitrary log level
void log(S...)(LogLevel level, S args) { static public void log(S...)(LogLevel level, S args) {
if (logLevel >= level && logFile.isOpen) { if (logLevel >= level && logFile !is null && logFile.isOpen) {
SysTime ts = Clock.currTime(); SysTime ts = Clock.currTime();
logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level)); logFile.writef("%04d-%02d-%02d %02d:%02d:%02d.%03d %s ", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fracSecs.split!("msecs").msecs, logLevelName(level));
logFile.writeln(args); logFile.writeln(args);
@ -123,34 +146,46 @@ synchronized class Log {
} }
} }
/// Log verbose / trace message /// Log verbose / trace message
void v(S...)(S args) { static public void v(S...)(S args) {
if (logLevel >= LogLevel.Trace && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Trace, args); if (logLevel >= LogLevel.Trace && logFile !is null && logFile.isOpen)
log(LogLevel.Trace, args);
}
} }
/// Log debug message /// Log debug message
void d(S...)(S args) { static public void d(S...)(S args) {
if (logLevel >= LogLevel.Debug && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Debug, args); if (logLevel >= LogLevel.Debug && logFile !is null && logFile.isOpen)
log(LogLevel.Debug, args);
}
} }
/// Log info message /// Log info message
void i(S...)(S args) { static public void i(S...)(S args) {
if (logLevel >= LogLevel.Info && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Info, args); if (logLevel >= LogLevel.Info && logFile !is null && logFile.isOpen)
log(LogLevel.Info, args);
}
} }
/// Log warn message /// Log warn message
void w(S...)(S args) { static public void w(S...)(S args) {
if (logLevel >= LogLevel.Warn && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Warn, args); if (logLevel >= LogLevel.Warn && logFile !is null && logFile.isOpen)
log(LogLevel.Warn, args);
}
} }
/// Log error message /// Log error message
void e(S...)(S args) { static public void e(S...)(S args) {
if (logLevel >= LogLevel.Error && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Error, args); if (logLevel >= LogLevel.Error && logFile !is null && logFile.isOpen)
log(LogLevel.Error, args);
}
} }
/// Log fatal error message /// Log fatal error message
void f(S...)(S args) { static public void f(S...)(S args) {
if (logLevel >= LogLevel.Fatal && logFile.isOpen) synchronized(mutex) {
log(LogLevel.Fatal, args); if (logLevel >= LogLevel.Fatal && logFile !is null && logFile.isOpen)
log(LogLevel.Fatal, args);
}
} }
} }
@ -168,3 +203,4 @@ debug {
void onResourceDestroyWhileShutdown(string resourceName, string objname = null) { void onResourceDestroyWhileShutdown(string resourceName, string objname = null) {
Log.e("Resource leak: destroying resource while shutdown! ", resourceName, " ", objname); Log.e("Resource leak: destroying resource while shutdown! ", resourceName, " ", objname);
} }

View File

@ -9,6 +9,8 @@ Authors: Vadim Lopatin, coolreader.org@gmail.com
*/ */
module dlangui.graphics.ftfonts; module dlangui.graphics.ftfonts;
version(USE_FREETYPE):
import dlangui.graphics.fonts; import dlangui.graphics.fonts;
import derelict.freetype.ft; import derelict.freetype.ft;
@ -524,12 +526,16 @@ class FreeTypeFontManager : FontManager {
this() { this() {
// load dynaic library // load dynaic library
try { try {
Log.v("DerelictFT: Loading FreeType library");
DerelictFT.missingSymbolCallback = &missingSymFunc; DerelictFT.missingSymbolCallback = &missingSymFunc;
Log.v("DerelictFT: Missing symbols callback is registered");
DerelictFT.load(); DerelictFT.load();
} catch (Exception e) { Log.v("DerelictFT: Loaded");
} catch (Throwable e) {
Log.e("Derelict: cannot load freetype shared library: ", e.msg); Log.e("Derelict: cannot load freetype shared library: ", e.msg);
throw new Exception("Cannot load freetype library"); throw new Exception("Cannot load freetype library");
} }
Log.v("Initializing FreeType library");
// init library // init library
int error = FT_Init_FreeType(&_library); int error = FT_Init_FreeType(&_library);
if (error) { if (error) {

View File

@ -1416,8 +1416,11 @@ version (Windows) {
try { try {
/// testing freetype font manager /// testing freetype font manager
version(USE_FREETYPE) { version(USE_FREETYPE) {
Log.v("Trying to init FreeType font manager");
import dlangui.graphics.ftfonts; import dlangui.graphics.ftfonts;
// trying to create font manager // trying to create font manager
Log.v("Creating FreeTypeFontManager");
FreeTypeFontManager ftfontMan = new FreeTypeFontManager(); FreeTypeFontManager ftfontMan = new FreeTypeFontManager();
import win32.shlobj; import win32.shlobj;
@ -1444,6 +1447,7 @@ version (Windows) {
} }
} }
} }
Log.v("Registering fonts");
ftfontMan.registerFont(fontsPath ~ "arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal); ftfontMan.registerFont(fontsPath ~ "arial.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Normal);
ftfontMan.registerFont(fontsPath ~ "arialbd.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold); ftfontMan.registerFont(fontsPath ~ "arialbd.ttf", FontFamily.SansSerif, "Arial", false, FontWeight.Bold);
ftfontMan.registerFont(fontsPath ~ "arialbi.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold); ftfontMan.registerFont(fontsPath ~ "arialbi.ttf", FontFamily.SansSerif, "Arial", true, FontWeight.Bold);
@ -1590,9 +1594,13 @@ void releaseResourcesOnAppExit() {
void initLogs() { void initLogs() {
version (Windows) { version (Windows) {
debug { debug {
Log.setFileLogger(std.stdio.File("ui.log", "w")); Log.setFileLogger(new std.stdio.File("ui.log", "w"));
} else { } else {
// no logging // no logging unless version ForceLogs is set
version(ForceLogs) {
Log.setFileLogger(new std.stdio.File("ui.log", "w"));
Log.i("Logging to file ui.log");
}
} }
} else { } else {
Log.setStderrLogger(); Log.setStderrLogger();
@ -1600,6 +1608,13 @@ void initLogs() {
debug { debug {
Log.setLogLevel(LogLevel.Trace); Log.setLogLevel(LogLevel.Trace);
} else { } else {
Log.setLogLevel(LogLevel.Warn); version(ForceLogs) {
Log.setLogLevel(LogLevel.Trace);
Log.i("Log level: trace");
} else {
Log.setLogLevel(LogLevel.Warn);
Log.i("Log level: warn");
}
} }
Log.i("Logger is initialized");
} }

View File

@ -905,8 +905,7 @@ int DLANGUIWinMain(void* hInstance, void* hPrevInstance,
char* lpCmdLine, int nCmdShow) { char* lpCmdLine, int nCmdShow) {
int result; int result;
try try {
{
Runtime.initialize(); Runtime.initialize();
// call SetProcessDPIAware to support HI DPI - fix by Kapps // call SetProcessDPIAware to support HI DPI - fix by Kapps
@ -973,7 +972,9 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
_cmdShow = iCmdShow; _cmdShow = iCmdShow;
_hInstance = hInstance; _hInstance = hInstance;
Log.v("Creating platform");
w32platform = new Win32Platform(); w32platform = new Win32Platform();
Log.v("Registering window class");
if (!w32platform.registerWndClass()) { if (!w32platform.registerWndClass()) {
MessageBoxA(null, "This program requires Windows NT!", "DLANGUI App".toStringz, MB_ICONERROR); MessageBoxA(null, "This program requires Windows NT!", "DLANGUI App".toStringz, MB_ICONERROR);
return 0; return 0;
@ -981,6 +982,7 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
Platform.setInstance(w32platform); Platform.setInstance(w32platform);
Log.v("Initializing font manager");
if (!initFontManager()) { if (!initFontManager()) {
Log.e("******************************************************************"); Log.e("******************************************************************");
Log.e("No font files found!!!"); Log.e("No font files found!!!");