I'm using AngelCodeFont because I couldn't get UnicodeFont to work on my first few tries.
I'm getting weird behavior where I pass in a string and another string is printed. The following screen shot shows "region..." being printed in the incorrect location and map name be completely wrong.
I investigated a bit in the source. I think I found the problem (I haven't tried it since I don't have the slick build configured on here):
Code:
DisplayList displayList = (DisplayList)displayLists.get(text+""+startIndex+""+endIndex);
The following line is very inefficient (using string cat to build a key) and has an unneeded risk of collision:
The key "(...)4011" can be refer to many different text output, even if it is improbable.
The following snippet is a simple solution that is very efficient for the frequent case of printing a string from start to finish and is more like to find an item in cache ( {"aheya",start=1,end=4} == {"hey",start=0,end=3}. Another solution is to create an object key and implement equals/hashcode correctly.
Code:
String key = text;
if( startIndex != 0 || endIndex != key.length() ) key = text.substring(...);
DisplayList displayList = (DisplayList)displayLists.get(key);
The real bug however happens when the cache is full. I don't understand how eldestDisplayListID/eldestDisplayList is being populated. Its getting invoked from an overwritten protected method so it might be worth while double checking it. Assuming it is correct the remove is done on eldestDisplayList.text which is not the correct key format (text+startIndex+endIndex):
Code:
// Compile a new display list.
displayList = new DisplayList();
displayList.text = text;
int displayListCount = displayLists.size();
if (displayListCount < DISPLAY_LIST_CACHE_SIZE) {
displayList.id = baseDisplayListID + displayListCount;
} else {
displayList.id = eldestDisplayListID;
displayLists.remove(eldestDisplayList.text);
}
displayLists.put(text+""+startIndex+""+endIndex, displayList);
GL.glNewList(displayList.id, SGL.GL_COMPILE_AND_EXECUTE);
render(text, startIndex, endIndex);
GL.glEndList();
So what I believe happens is the remove is incorrect so it believes the string is still in the cache when the id now belongs to a new string.