luqui / graphics-drawingcombinators

Combinators for drawing 2D shapes and images in Haskell (using OpenGL)
32 stars 16 forks source link

add withFont #14

Closed yairchu closed 9 years ago

yairchu commented 9 years ago

withFont is a safer way to create and destroy fonts. Using openFont cause rare crashes (see report below). System.Mem.Weak.addFinalizer's docs links to the Weak type's docs which explains: "attempting to place a finalizer on an ordinary Haskell type may well result in the finalizer running earlier than you expected", which is exactly what happens in our app, causing a crash..

Crash report: ... Thread 8 Crashed: 0 libGL.dylib 0x00007fff8ac574bd glDeleteTextures + 18 1 libftgl.2.dylib 0x00000001109137de FTBufferFontImpl::~FTBufferFontImpl() + 40 2 libftgl.2.dylib 0x000000011091378d FTBufferFontImpl::~FTBufferFontImpl() + 15 3 libftgl.2.dylib 0x0000000110913475 FTBufferFont::~FTBufferFont() + 15 4 libftgl.2.dylib 0x00000001109129b0 ftglDestroyFont + 28 5 lamdu 0x000000010e9aa94a c74y_info + 18 ... Thread 0:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x00007fff91da54de mach_msg_trap + 10 1 libsystem_kernel.dylib 0x00007fff91da464f mach_msg + 55 2 com.apple.framework.IOKit 0x00007fff8f8a916c io_connect_method + 381 3 com.apple.framework.IOKit 0x00007fff8f84c936 IOConnectCallMethod + 265 4 com.apple.IOAccelerator 0x00007fff8ea2f22a ioAccelResourceFinalize + 127 5 com.apple.CoreFoundation 0x00007fff92e6be8e CFRelease + 526 6 libGPUSupportMercury.dylib 0x00007fff8a460d26 gpusGetKernelTexture + 181 7 com.apple.driver.AppleIntelHD4000GraphicsGLDriver 0x0000123400401ada glrUpdateTexture + 7372 8 libGPUSupportMercury.dylib 0x00007fff8a4609cd gldModifyTexSubImage + 185 9 GLEngine 0x00007fff8415d946 glTexImage2DExec + 2097 10 libGL.dylib 0x00007fff8ac5946d glTexImage2D + 77 11 libftgl.2.dylib 0x0000000110913d8f FTPoint FTBufferFontImpl::RenderI(char const, int, FTPoint, FTPoint, int) + 1121 12 libftgl.2.dylib 0x00000001109138de FTBufferFontImpl::Render(char const_, int, FTPoint, FTPoint, int) + 56 13 libftgl.2.dylib 0x000000011091130f FTFont::Render(char const*, int, FTPoint, FTPoint, int) + 67 14 libftgl.2.dylib 0x0000000110912f7d ftglRenderFont + 120 15 lamdu 0x000000010e7bcbe3 cgBR_info + 27

luqui commented 9 years ago

Thank you!