View Issue Details

IDProjectCategoryView StatusLast Update
0033668Open CASCADEOCCT:Codingpublic2024-07-07 22:11
Reportervtryputs Assigned Tovtryputs  
PrioritynormalSeverityminor 
Status feedbackResolutionopen 
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)
  • emsdk version 3.1.52.png (68,728 bytes)
  • emsdk version 3.1.61.png (62,599 bytes)

Activities

vtryputs

2024-04-05 17:15

developer  

image.png (61,105 bytes)

hossamali

2024-07-02 13:51

developer   ~0116105

Last edited: 2024-07-02 13:52

Analysis
Using the given playground, it was found that there is a memory leak and after the investigation and profiling of the memory, it was found that the leak happens only when using emsdk version 3.1.52 but when upgrading the emsdk version to 3.1.61 the memory leak didn't happen. check below memory report before and after changing emsdk version

Conclusion
it seems that the problem is related to an internal mechanism in the older emsdk version after checking with the issue reporter there is no technical issue with upgrading to the most recent emsk version to fix the problem
emsdk version 3.1.52.png (68,728 bytes)
emsdk version 3.1.61.png (62,599 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
2024-05-16 14:22 ebelouso Assigned To dpasukhi => hossamali
2024-07-02 13:51 hossamali Note Added: 0116105
2024-07-02 13:51 hossamali File Added: emsdk version 3.1.52.png
2024-07-02 13:51 hossamali File Added: emsdk version 3.1.61.png
2024-07-02 13:52 hossamali Note Edited: 0116105
2024-07-02 13:54 hossamali Assigned To hossamali => vtryputs
2024-07-02 13:54 hossamali Status new => resolved
2024-07-07 22:11 dpasukhi Status resolved => feedback