MantisBT
Mantis Bug Tracker Workflow

View Revisions: Issue #31785 All Revisions ] Back to Issue ]
Summary 0031785: [REGRESSION] Application Framework - application crashes on reading XBF document in background thread
Revision 2020-09-23 15:55 by mpv
Steps To Reproduce bugs caf bug31785
Revision 2020-09-22 15:23 by mpv
Steps To Reproduce Not required
Revision 2020-09-22 09:39 by kgv
Steps To Reproduce

#include <BinXCAFDrivers.hxx>
#include <Message.hxx>
#include <OSD_Thread.hxx>
#pragma comment(lib, "TKBinXCAF.lib")
namespace
{
  class QABugs_XdeLoader : public OSD_Thread
  {
  public:
    QABugs_XdeLoader (const Handle(TDocStd_Application)& theXdeApp,
                      const Handle(TDocStd_Document)&    theXdeDoc,
                      const TCollection_AsciiString&     theFilePath)
    : OSD_Thread (performThread),
      myXdeApp (theXdeApp), myXdeDoc (theXdeDoc), myFilePath (theFilePath) {}

  private:
    void perform()
    {        
      Handle(TDocStd_Document) aNewDoc;
      const PCDM_ReaderStatus aReaderStatus =
        myXdeApp->Open (myFilePath, aNewDoc);
      if (aReaderStatus != PCDM_RS_OK)
      {
        Message::SendFail ("Error occurred while reading the file");
        return;
      }
      myXdeDoc = aNewDoc;
      Message::SendInfo() << "Info: document has been opened";
    }

    static Standard_Address performThread (Standard_Address theData)
    {
      QABugs_XdeLoader* aLoader = (QABugs_XdeLoader* )theData;
      OSD::SetThreadLocalSignal (OSD_SignalMode_Set, false);
      try
      {
        OCC_CATCH_SIGNALS
        aLoader->perform();
      }
      catch (Standard_Failure const& theExcep)
      {
        Message::SendFail() << "Error: unhandled exception " << theExcep;
      }
      return 0;
    }
  private:
    Handle(TDocStd_Application) myXdeApp;
    Handle(TDocStd_Document)    myXdeDoc;
    TCollection_AsciiString     myFilePath;
  };
}

//=======================================================================
//function : OCC31785
//purpose  : Try reading XBF file in background thread
//=======================================================================
static Standard_Integer OCC31785 (Draw_Interpretor& theDI,
                                  Standard_Integer theNbArgs,
                                  const char** theArgVec)
{
  if (theNbArgs != 2)
  {
    theDI << "Syntax error: wrong number of arguments\n";
    return 1;
  }

  TCollection_AsciiString aFileName (theArgVec[1]);

  Handle(TDocStd_Application) anXdeApp = new TDocStd_Application();
  BinXCAFDrivers::DefineFormat (anXdeApp);

  Handle(TDocStd_Document) anXdeDoc;
  anXdeApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), anXdeDoc);
  QABugs_XdeLoader aLoader (anXdeApp, anXdeDoc, aFileName);
  aLoader.Run (&aLoader);
  aLoader.Wait();
  return 0;
}
...
  theCommands.Add("OCC31785",
                  "OCC31785 file.xbf : test reading XBF file in another thread",
                  __FILE__, OCC31785, group);


pload OCAF XDE QAcommands
XNewDoc D
XSave D test.xbf
Close D
OCC31785 test.xbf
Revision 2020-09-21 23:42 by kgv
Steps To Reproduce

#include <BinXCAFDrivers.hxx>
#include <Message.hxx>
#include <OSD_Thread.hxx>
#pragma comment(lib, "TKBinXCAF.lib")
namespace
{
  class QABugs_XdeLoader : public OSD_Thread
  {
  public:
    QABugs_XdeLoader (const Handle(TDocStd_Application)& theXdeApp,
                      const Handle(TDocStd_Document)&    theXdeDoc,
                      const TCollection_AsciiString&     theFilePath)
    : OSD_Thread (performThread),
      myXdeApp (theXdeApp), myXdeDoc (theXdeDoc), myFilePath (theFilePath) {}

  private:
    void perform()
    {        
      Handle(TDocStd_Document) aNewDoc;
      const PCDM_ReaderStatus aReaderStatus = myXdeApp->Open (myFilePath, aNewDoc);
      if (aReaderStatus != PCDM_RS_OK)
      {
        Message::SendFail ("Error occurred while reading the file");
        return;
      }
      myXdeDoc = aNewDoc;
    }

    static Standard_Address performThread (Standard_Address theData)
    {
      QABugs_XdeLoader* aLoader = (QABugs_XdeLoader* )theData;
      OSD::SetThreadLocalSignal (OSD_SignalMode_Set, false);
      try
      {
        OCC_CATCH_SIGNALS
        aLoader->perform();
      }
      catch (Standard_Failure const& theExcep)
      {
        std::cout << "Error: unhandled exception " << theExcep << "\n";
      
}
      return 0;
    }
  private:
    Handle(TDocStd_Application) myXdeApp;
    Handle(TDocStd_Document)    myXdeDoc;
    TCollection_AsciiString     myFilePath;
  };
}

//=======================================================================
//function : OCC31785
//purpose  : Try reading XBF file in background thread
//=======================================================================
static Standard_Integer OCC31785 (Draw_Interpretor& theDI,
                                  Standard_Integer theNbArgs,
                                  const char** theArgVec)
{
  if (theNbArgs != 2)
  {
    theDI << "Syntax error: wrong number of arguments\n";
    return 1;
  }

  TCollection_AsciiString aFileName (theArgVec[1]);

  Handle(TDocStd_Application) anXdeApp = new TDocStd_Application();
  BinXCAFDrivers::DefineFormat (anXdeApp);

  Handle(TDocStd_Document) anXdeDoc;
  anXdeApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), anXdeDoc);
  QABugs_XdeLoader aLoader (anXdeApp, anXdeDoc, aFileName);
  aLoader.Run (&aLoader);
  aLoader.Wait();
  return 0;
}
...
  theCommands.Add("OCC31785", "OCC31785 file.xbf : test reading XBF file in another thread", 
__FILE__, OCC31785, group);


pload OCAF XDE QAcommands
XNewDoc D
XSave D test.xbf
Close D
OCC31785 test.xbf
Revision 2020-09-21 22:14 by kgv
Steps To Reproduce


Copyright © 2000 - 2020 MantisBT Team
Powered by Mantis Bugtracker