Changed: #1092 Reliability improvements for batched anim export from max
This commit is contained in:
parent
ccd5c879f6
commit
9f256c4d4b
4 changed files with 136 additions and 57 deletions
|
@ -766,7 +766,7 @@ static INT_PTR CALLBACK CNelExportDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LP
|
||||||
|
|
||||||
|
|
||||||
//--- CNelExport -------------------------------------------------------
|
//--- CNelExport -------------------------------------------------------
|
||||||
CNelExport::CNelExport()
|
CNelExport::CNelExport() : _ErrorInDialog(true), _TerminateOnFileOpenIssues(false)
|
||||||
{
|
{
|
||||||
_Ip = NULL;
|
_Ip = NULL;
|
||||||
theHPanel = NULL;
|
theHPanel = NULL;
|
||||||
|
@ -869,3 +869,11 @@ void CNelExport::init (bool view, bool errorInDialog, Interface *ip, bool loadSt
|
||||||
// Create the CExportNel class
|
// Create the CExportNel class
|
||||||
_ExportNel = new CExportNel (errorInDialog, view, view, ip, "NeL Export", &theExportSceneStruct);
|
_ExportNel = new CExportNel (errorInDialog, view, view, ip, "NeL Export", &theExportSceneStruct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nelExportTerminateProcess()
|
||||||
|
{
|
||||||
|
DWORD ec = 0;
|
||||||
|
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId());
|
||||||
|
GetExitCodeProcess(h, &ec);
|
||||||
|
TerminateProcess(h, ec);
|
||||||
|
}
|
||||||
|
|
|
@ -99,10 +99,13 @@ public:
|
||||||
Interface *_Ip;
|
Interface *_Ip;
|
||||||
|
|
||||||
// View
|
// View
|
||||||
bool _View;
|
// bool _View;
|
||||||
|
|
||||||
// View
|
// View
|
||||||
bool _ErrorInDialog;
|
bool _ErrorInDialog;
|
||||||
|
|
||||||
|
// Handle problematic file handles with max.
|
||||||
|
bool _TerminateOnFileOpenIssues;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CNelExportClassDesc:public ClassDesc2
|
class CNelExportClassDesc:public ClassDesc2
|
||||||
|
@ -122,5 +125,7 @@ extern CNelExportClassDesc CNelExportDesc;
|
||||||
|
|
||||||
extern CNelExport theCNelExport;
|
extern CNelExport theCNelExport;
|
||||||
|
|
||||||
|
void nelExportTerminateProcess();
|
||||||
|
|
||||||
|
|
||||||
#endif // __NEL_EXPORT__H
|
#endif // __NEL_EXPORT__H
|
||||||
|
|
|
@ -132,6 +132,8 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nlwarning("Failed to create file %s", tempFileName);
|
nlwarning("Failed to create file %s", tempFileName);
|
||||||
|
if (_TerminateOnFileOpenIssues)
|
||||||
|
nelExportTerminateProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the pointer
|
// Delete the pointer
|
||||||
|
@ -172,6 +174,8 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nlwarning("Failed to open file: %s", tempFileName);
|
nlwarning("Failed to open file: %s", tempFileName);
|
||||||
|
if (_TerminateOnFileOpenIssues)
|
||||||
|
nelExportTerminateProcess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
|
@ -246,6 +250,17 @@ bool CNelExport::exportAnim (const char *sPath, std::vector<INode*>& vectNode, T
|
||||||
{
|
{
|
||||||
// Result to return
|
// Result to return
|
||||||
bool bRet=false;
|
bool bRet=false;
|
||||||
|
char tempFileName[MAX_PATH] = { 0 };
|
||||||
|
char tempPathBuffer[MAX_PATH] = { 0 };
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DWORD dwRetVal = GetTempPathA(MAX_PATH, tempPathBuffer);
|
||||||
|
if (dwRetVal > MAX_PATH || (dwRetVal == 0))
|
||||||
|
nlerror("GetTempPath failed");
|
||||||
|
UINT uRetVal = GetTempFileNameA(tempPathBuffer, TEXT("_nel_export_mesh_"), 0, tempFileName);
|
||||||
|
if (uRetVal == 0)
|
||||||
|
nlerror("GetTempFileName failed");
|
||||||
|
|
||||||
// Create an animation file
|
// Create an animation file
|
||||||
CAnimation animFile;
|
CAnimation animFile;
|
||||||
|
@ -282,15 +297,48 @@ bool CNelExport::exportAnim (const char *sPath, std::vector<INode*>& vectNode, T
|
||||||
{
|
{
|
||||||
// Open a file
|
// Open a file
|
||||||
COFile file;
|
COFile file;
|
||||||
if (file.open (sPath))
|
if (file.open (tempFileName))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
nldebug("Serialize the animation");
|
||||||
// Serial the animation
|
// Serial the animation
|
||||||
animFile.serial (file);
|
animFile.serial (file);
|
||||||
|
// Close the file
|
||||||
|
file.close();
|
||||||
// All is good
|
// All is good
|
||||||
bRet=true;
|
bRet=true;
|
||||||
|
// Verify the file
|
||||||
|
nldebug("Verify exported anim file");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool tempBRet = bRet;
|
||||||
|
bRet = false;
|
||||||
|
CIFile vf;
|
||||||
|
if (vf.open(tempFileName))
|
||||||
|
{
|
||||||
|
nldebug("File opened, size: %u", vf.getFileSize());
|
||||||
|
CAnimation a;
|
||||||
|
a.serial(vf);
|
||||||
|
nldebug("Anim serialized");
|
||||||
|
vf.close();
|
||||||
|
nldebug("File closed");
|
||||||
|
bRet = tempBRet;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlwarning("Failed to open file: %s", tempFileName);
|
||||||
|
bRet = false;
|
||||||
|
if (_TerminateOnFileOpenIssues)
|
||||||
|
nelExportTerminateProcess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
nlwarning("Failed to verify shape. Must crash now.");
|
||||||
|
remove(tempFileName);
|
||||||
|
bRet = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception& e)
|
catch (Exception& e)
|
||||||
{
|
{
|
||||||
|
@ -305,9 +353,31 @@ bool CNelExport::exportAnim (const char *sPath, std::vector<INode*>& vectNode, T
|
||||||
if (_ErrorInDialog)
|
if (_ErrorInDialog)
|
||||||
MessageBox (NULL, "Can't open the file for writing.", "NeL export", MB_OK|MB_ICONEXCLAMATION);
|
MessageBox (NULL, "Can't open the file for writing.", "NeL export", MB_OK|MB_ICONEXCLAMATION);
|
||||||
else
|
else
|
||||||
nlwarning ("ERROR : Can't open the file (%s) for writing", sPath);
|
nlwarning ("ERROR : Can't open the file (%s) for writing", tempFileName);
|
||||||
|
if (_TerminateOnFileOpenIssues)
|
||||||
|
nelExportTerminateProcess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
nlwarning("Fatal exception at CNelExport::exportAnim.");
|
||||||
|
bRet = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bRet)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
remove(sPath);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
CFile::moveFile(sPath, tempFileName);
|
||||||
|
nlinfo("MOVE %s -> %s", tempFileName, sPath);
|
||||||
|
}
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -945,10 +945,7 @@ protected:
|
||||||
/// Put the string into the file.
|
/// Put the string into the file.
|
||||||
virtual void doDisplay( const CLog::TDisplayInfo& args, const char *message )
|
virtual void doDisplay( const CLog::TDisplayInfo& args, const char *message )
|
||||||
{
|
{
|
||||||
DWORD ec = 0;
|
nelExportTerminateProcess();
|
||||||
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId());
|
|
||||||
GetExitCodeProcess(h, &ec);
|
|
||||||
TerminateProcess(h, ec);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -958,6 +955,8 @@ Value* force_quit_on_msg_displayer_cf(Value** arg_list, int count)
|
||||||
// disable the Windows popup telling that the application aborted and disable the dr watson report.
|
// disable the Windows popup telling that the application aborted and disable the dr watson report.
|
||||||
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||||
putenv("NEL_IGNORE_ASSERT=1");
|
putenv("NEL_IGNORE_ASSERT=1");
|
||||||
|
theCNelExport._ErrorInDialog = false;
|
||||||
|
theCNelExport._TerminateOnFileOpenIssues = true;
|
||||||
if (NLMISC::DefaultMsgBoxDisplayer || INelContext::getInstance().getDefaultMsgBoxDisplayer())
|
if (NLMISC::DefaultMsgBoxDisplayer || INelContext::getInstance().getDefaultMsgBoxDisplayer())
|
||||||
{
|
{
|
||||||
if (!NLMISC::DefaultMsgBoxDisplayer)
|
if (!NLMISC::DefaultMsgBoxDisplayer)
|
||||||
|
@ -978,10 +977,7 @@ Value* force_quit_right_now_cf(Value** arg_list, int count)
|
||||||
{
|
{
|
||||||
// because quitMAX can fail
|
// because quitMAX can fail
|
||||||
nlwarning("Force quit");
|
nlwarning("Force quit");
|
||||||
DWORD ec = 0;
|
nelExportTerminateProcess();
|
||||||
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId());
|
|
||||||
GetExitCodeProcess(h, &ec);
|
|
||||||
TerminateProcess(h, ec);
|
|
||||||
return &true_value;
|
return &true_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue