diff --git a/src/dlangui/graphics/gldrawbuf.d b/src/dlangui/graphics/gldrawbuf.d index 2eb772b5..71df709a 100644 --- a/src/dlangui/graphics/gldrawbuf.d +++ b/src/dlangui/graphics/gldrawbuf.d @@ -344,7 +344,7 @@ private abstract class GLCache if (!_texture.ID) return; } - Log.d("updateTexture for cache page - setting image ", _drawbuf.width, "x", _drawbuf.height, " tx=", _texture.ID); + Log.d("updateTexture for cache page - setting image ", _drawbuf.width, "x", _drawbuf.height, " tx=", _texture ? _texture.ID : 0); uint * pixels = _drawbuf.scanLine(0); if (!glSupport.setTextureImage(_texture, _drawbuf.width, _drawbuf.height, cast(ubyte*)pixels)) { destroy(_texture); @@ -527,7 +527,7 @@ private class GLImageCache : GLCache void drawItem(GLCacheItem item, Rect dstrc, Rect srcrc, uint color, uint options, Rect * clip, int rotationAngle) { if (_needUpdateTexture) updateTexture(); - if (_texture.ID != 0) { + if (_texture && _texture.ID != 0) { //rotationAngle = 0; int rx = dstrc.middlex; int ry = dstrc.middley; @@ -628,7 +628,7 @@ private class GLGlyphCache : GLCache void drawItem(GLCacheItem item, Rect dstrc, Rect srcrc, uint color, Rect * clip) { if (_needUpdateTexture) updateTexture(); - if (_texture.ID != 0) { + if (_texture && _texture.ID != 0) { // convert coordinates to cached texture srcrc.offset(item._rc.left, item._rc.top); if (clip) { diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d index 81fbc9ff..964a5cec 100644 --- a/src/dlangui/platforms/windows/winapp.d +++ b/src/dlangui/platforms/windows/winapp.d @@ -167,8 +167,15 @@ static if (ENABLE_OPENGL) { bool _error; /// Init OpenGL context, if not yet initialized bool init(HDC hDC) { - if (_hGLRC) + if (_hGLRC) { + // just setup pixel format + if (setupPixelFormat(hDC)) { + Log.i("OpenGL context already exists. Setting pixel format."); + } else { + Log.e("Cannot setup pixel format"); + } return true; + } if (_error) return false; if (setupPixelFormat(hDC)) { @@ -203,11 +210,15 @@ static if (ENABLE_OPENGL) { } /// make this context current for DC void bind(HDC hDC) { - wglMakeCurrent(hDC, _hGLRC); + if (!wglMakeCurrent(hDC, _hGLRC)) { + import std.string : format; + Log.e("wglMakeCurrent is failed. GetLastError=%x".format(GetLastError())); + } } /// make null context current for DC void unbind(HDC hDC) { - wglMakeCurrent(hDC, null); + //wglMakeCurrent(hDC, null); + wglMakeCurrent(null, null); } void swapBuffers(HDC hDC) { SwapBuffers(hDC); @@ -312,7 +323,7 @@ class Win32Window : Window { } buf.afterDrawing(); sharedGLContext.swapBuffers(hdc); - sharedGLContext.unbind(hdc); + //sharedGLContext.unbind(hdc); destroy(buf); } }