Bart van Strien avatar Bart van Strien committed df78a85

Improve compatibility check (I still can't believe robin was right)

Comments (0)

Files changed (8)

src/modules/font/freetype/Font.h

 } // font
 } // love
 
-#endif // LOVE_FONT_FREETYPE_FONT_H
+#endif // LOVE_FONT_FREETYPE_FONT_H

src/modules/font/freetype/TrueTypeRasterizer.cpp

 		metrics.ascent = s.ascender >> 6;
 		metrics.descent = s.descender >> 6;
 		metrics.height = s.height >> 6;
+
+		ref = WeakReference::obtain(this);
 	}
 
 	TrueTypeRasterizer::~TrueTypeRasterizer()
 	{
+		ref->destroy();
+		ref->release();
+
 		FT_Done_Face(face);
 		data->release();
 	}
 
 } // freetype
 } // font
-} // love
+} // love

src/modules/font/freetype/TrueTypeRasterizer.h

 // LOVE
 #include <filesystem/File.h>
 #include <font/Rasterizer.h>
+#include <common/WeakReference.h>
 
 // TrueType2
 #include <ft2build.h>
 
 		// File data
 		Data * data;
+
+		WeakReference * ref;
 		
 	public:
 		TrueTypeRasterizer(FT_Library library, Data * data, int size);
 } // font
 } // love
 
-#endif // LOVE_FONT_FREETYPE_TRUE_TYPE_RASTERIZER_H
+#endif // LOVE_FONT_FREETYPE_TRUE_TYPE_RASTERIZER_H

src/modules/font/freetype/wrap_Font.cpp

 			int size = luaL_checkint(L, 2);
 			t = instance->newRasterizer(d, size);
 		}
-		
+
 		luax_newtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
 		return 1;
 	}

src/modules/graphics/opengl/Font.cpp

 {
 
 	Font::Font(love::font::Rasterizer * r, const Image::Filter& filter)
-	: rasterizer(r), height(r->getHeight()), lineHeight(1), mSpacing(1), filter(filter)
+	: height(r->getHeight()), lineHeight(1), mSpacing(1), filter(filter)
 	{
-		r->retain();
+		rasterizer = WeakReference::obtain(r);
 		love::font::GlyphData * gd = r->getGlyphData(32);
 		type = (gd->getFormat() == love::font::GlyphData::FORMAT_LUMINANCE_ALPHA ? FONT_TRUETYPE : FONT_IMAGE);
 		delete gd;
 
 	Font::~Font()
 	{
+		rasterizer->destroy();
 		rasterizer->release();
 		unloadVolatile();
 	}
 	
 	Font::Glyph * Font::addGlyph(int glyph)
 	{
+		if (!rasterizer->isValid) return 0;
+		love::font::Rasterizer *r = (love::font::Rasterizer*) rasterizer->getData();
 		Glyph * g = new Glyph;
 		g->list = glGenLists(1);
 		if (g->list == 0) { // opengl failed to generate the list
 			delete g;
 			return NULL;
 		}
-		love::font::GlyphData *gd = rasterizer->getGlyphData(glyph);
+		love::font::GlyphData *gd = r->getGlyphData(glyph);
 		g->spacing = gd->getAdvance();
 		int w = gd->getWidth();
 		int h = gd->getHeight();

src/modules/graphics/opengl/Font.h

 
 // LOVE
 #include <common/Object.h>
+#include <common/WeakReference.h>
 #include <font/Rasterizer.h>
 #include <graphics/Image.h>
 
 			int spacing;
 		};
 		
-		love::font::Rasterizer * rasterizer;
+		WeakReference *rasterizer;
 
 		int height;
 		float lineHeight;

src/scripts/boot.lua

 	for i, v in ipairs(love._version_compat) do
 		if c.version == v then
 			compat = true
+			break
 		end
 	end
 	if not compat then

src/scripts/boot.lua.h

 	0x09, 0x09, 0x69, 0x66, 0x20, 0x63, 0x2e, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x3d, 0x20, 
 	0x76, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x09, 0x09, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a,
+	0x09, 0x09, 0x09, 0x62, 0x72, 0x65, 0x61, 0x6b, 0x0a,
 	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x65, 0x6e, 0x64, 0x0a,
 	0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x20, 0x74, 0x68, 0x65, 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.