app_server: FontStyle lifecycle
FontFamily is babysitted by the FontManager. It doesn't own FontStyle references, there's no place in it to release them. FontManager owns a reference to the FontStyle, and it is in fStyleHashTable. Putting a style there acquires a new reference, so we can release the one from the new style. Removing a style from the map releases the reference. We need to clear the map before shutting down FreeType to get rid of our last references and let the styles die now instead of afterwards to avoid double freeing the faces. These solve the new crash from the previous patch. It didn't crash before because even after the map was destroyed there were still dangling references to the styles. On removing a user font, the style will remove itself from the family through the manager if that was the last reference, and the manager will remove and delete the family if it has no more styles. Change-Id: I460ff830fa8a8a5adb90dc8ea12120e1e50a5912 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6052 Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
6d024fde1c
commit
a34c877fd0
@ -1766,12 +1766,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
||||
status_t status = B_OK;
|
||||
|
||||
AutoLocker<FontManagerBase> fontLock(fAppFontManager);
|
||||
FontStyle* style = fAppFontManager->GetStyle(familyID, styleID);
|
||||
|
||||
if (style != NULL) {
|
||||
status = fAppFontManager->RemoveUserFont(familyID, styleID);
|
||||
} else
|
||||
status = B_BAD_VALUE;
|
||||
|
||||
fLink.StartMessage(status);
|
||||
fLink.Flush();
|
||||
|
@ -95,6 +95,7 @@ AppFontManager::_AddUserFont(FT_Face face, node_ref nodeRef, const char* path,
|
||||
styleID = style->ID();
|
||||
|
||||
fStyleHashTable.Put(FontKey(familyID, styleID), style);
|
||||
style->ReleaseReference();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@ -160,19 +161,7 @@ AppFontManager::RemoveUserFont(uint16 familyID, uint16 styleID)
|
||||
ASSERT(IsLocked());
|
||||
|
||||
FontKey fKey(familyID, styleID);
|
||||
FontStyle* styleRef = fStyleHashTable.Get(fKey);
|
||||
fStyleHashTable.Remove(fKey);
|
||||
FontStyle* styleRef = fStyleHashTable.Remove(fKey);
|
||||
|
||||
FontFamily* family = styleRef->Family();
|
||||
bool removed = family->RemoveStyle(styleRef, this);
|
||||
|
||||
if (!removed)
|
||||
syslog(LOG_DEBUG, "AppFontManager::RemoveUserFont style not removed from family\n");
|
||||
|
||||
fFamilies.RemoveItem(family);
|
||||
delete family;
|
||||
|
||||
styleRef->ReleaseReference();
|
||||
|
||||
return B_OK;
|
||||
return styleRef != NULL ? B_OK : B_BAD_VALUE;
|
||||
}
|
||||
|
@ -78,8 +78,6 @@ FontFamily::~FontFamily()
|
||||
// we remove us before deleting the style, so that the font manager
|
||||
// is not contacted to remove the style from us
|
||||
style->_SetFontFamily(NULL, -1);
|
||||
|
||||
style->ReleaseReference();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,8 @@ FontManagerBase::~FontManagerBase()
|
||||
for (int32 i = fFamilies.CountItems(); i-- > 0;)
|
||||
delete fFamilies.ItemAt(i);
|
||||
|
||||
fStyleHashTable.Clear();
|
||||
|
||||
if (fHasFreetypeLibrary == true)
|
||||
FT_Done_FreeType(gFreeTypeLibrary);
|
||||
}
|
||||
@ -306,8 +308,10 @@ FontManagerBase::RemoveStyle(FontStyle* style)
|
||||
debugger("style removed but still available!");
|
||||
|
||||
if (family->RemoveStyle(style)
|
||||
&& family->CountStyles() == 0)
|
||||
&& family->CountStyles() == 0) {
|
||||
fFamilies.RemoveItem(family);
|
||||
delete family;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -484,8 +484,6 @@ GlobalFontManager::_RemoveStyle(font_directory& directory, FontStyle* style)
|
||||
directory.revision++;
|
||||
|
||||
fStyleHashTable.Remove(FontKey(style->Family()->ID(), style->ID()));
|
||||
|
||||
style->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
@ -741,6 +739,7 @@ GlobalFontManager::_AddFont(font_directory& directory, BEntry& entry)
|
||||
|
||||
directory.styles.AddItem(style);
|
||||
fStyleHashTable.Put(FontKey(style->Family()->ID(), style->ID()), style);
|
||||
style->ReleaseReference();
|
||||
|
||||
if (directory.AlreadyScanned())
|
||||
directory.revision++;
|
||||
|
Loading…
Reference in New Issue
Block a user