View Issue Details

IDProjectCategoryView StatusLast Update
0033668Open CASCADEOCCT:Codingpublic2024-04-05 17:22
Reportervtryputs Assigned Todpasukhi  
PrioritynormalSeverityminor 
Status newResolutionopen 
PlatformWasm 
Product Version7.8.0 
Summary0033668: Coding - Memory leak during call Font_FTFont::FindAndCreate
DescriptionMemory leak in wasm during call Font_FTFont::FindAndCreate after register the font using Font_FontMgr::GetInstance()->Register
Find some strange behavior with provided code: on wasm side it crashes the application because of out of memory (didn't reproduced the issue on native (ubuntu 22.04 application)), it only happens after register custom font using 'Font_FontMgr::GetInstance()->Register' on wasm.


OCCT commit: f60082f9fb70440a6e77c3e37918de166bacc264
Freetype commit: e4586d960f339cf75e2e0b34aee30a0ed8353c0d
Steps To Reproduce1. Load new font using:
void OccViewer::_cppRegisterFont (const std::string& theFontFile,
                                  const std::string& theFontName,
                                  bool               theToOverride)
{
  if (Handle (Font_SystemFont) aFont = Font_FontMgr::GetInstance()->CheckFont (theFontFile.c_str()))
  {
    if (!theFontName.empty())
    {
      Handle (Font_SystemFont) aFont2 = aFont;
      aFont                           = new Font_SystemFont (theFontName.c_str());
      for (int anAspectIter = 0; anAspectIter < Font_FontAspect_NB; ++anAspectIter)
      {
        aFont->SetFontPath ((Font_FontAspect)anAspectIter,
                            aFont2->FontPath ((Font_FontAspect)anAspectIter),
                            aFont2->FontFaceId ((Font_FontAspect)anAspectIter));
      }
    }
    Font_FontMgr::GetInstance()->RegisterFont (aFont, theToOverride);
    //const Handle (OccViewer)& anInstance = Instance();
    //const Handle (Prs3d_Drawer)& aDefaultDrawer = anInstance->Context()->DefaultDrawer();
    //Handle (Prs3d_TextAspect)    aTextAspect    = aDefaultDrawer->TextAspect();
    //aTextAspect->Aspect()->SetFont (aFont->FontName());
  }
  else
  {
    Message::DefaultMessenger()->SendFail() << "Error: font '" << theFontFile << "' is not found";
  }
}

2. Run provided code to reach out of memory

  auto findAndCreate = []()
  {
    Font_FTFontParams aFontParams;
    aFontParams.PointSize   = 10;
    aFontParams.Resolution  = 96;
    aFontParams.FontHinting = Font_Hinting_Off;

    Handle (Font_FTFont) aFont = Font_FTFont::FindAndCreate ("serif",
                                                             Font_FontAspect_Regular,
                                                             aFontParams);
  };

  for (int i = 0; i < 100; i++)
  {
    findAndCreate();
  }
TagsNo tags attached.
Test case number

Attached Files

  • image.png (61,105 bytes)

Activities

vtryputs

2024-04-05 17:15

developer  

image.png (61,105 bytes)

Issue History

Date Modified Username Field Change
2024-04-05 17:15 vtryputs New Issue
2024-04-05 17:15 vtryputs Assigned To => dpasukhi
2024-04-05 17:15 vtryputs File Added: image.png
2024-04-05 17:22 dpasukhi Platform => Wasm
2024-04-05 17:22 dpasukhi Summary Memory leak in wasm during call Font_FTFont::FindAndCreate after register the font using Font_FontMgr::GetInstance()->Register => Coding - Memory leak during call Font_FTFont::FindAndCreate
2024-04-05 17:22 dpasukhi Description Updated
2024-04-05 17:22 dpasukhi Steps to Reproduce Updated