Changed: #1092 Reliability improvements for batched anim export from max

This commit is contained in:
kaetemi 2010-09-26 17:00:01 +02:00
parent ccd5c879f6
commit 9f256c4d4b
4 changed files with 136 additions and 57 deletions

View file

@ -766,7 +766,7 @@ static INT_PTR CALLBACK CNelExportDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LP
//--- CNelExport -------------------------------------------------------
CNelExport::CNelExport()
CNelExport::CNelExport() : _ErrorInDialog(true), _TerminateOnFileOpenIssues(false)
{
_Ip = NULL;
theHPanel = NULL;
@ -869,3 +869,11 @@ void CNelExport::init (bool view, bool errorInDialog, Interface *ip, bool loadSt
// Create the CExportNel class
_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);
}

View file

@ -99,10 +99,13 @@ public:
Interface *_Ip;
// View
bool _View;
// bool _View;
// View
bool _ErrorInDialog;
// Handle problematic file handles with max.
bool _TerminateOnFileOpenIssues;
};
class CNelExportClassDesc:public ClassDesc2
@ -122,5 +125,7 @@ extern CNelExportClassDesc CNelExportDesc;
extern CNelExport theCNelExport;
void nelExportTerminateProcess();
#endif // __NEL_EXPORT__H

View file

@ -132,6 +132,8 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time)
else
{
nlwarning("Failed to create file %s", tempFileName);
if (_TerminateOnFileOpenIssues)
nelExportTerminateProcess();
}
// Delete the pointer
@ -172,6 +174,8 @@ bool CNelExport::exportMesh (const char *sPath, INode& node, TimeValue time)
else
{
nlwarning("Failed to open file: %s", tempFileName);
if (_TerminateOnFileOpenIssues)
nelExportTerminateProcess();
}
}
catch (...)
@ -246,6 +250,17 @@ bool CNelExport::exportAnim (const char *sPath, std::vector<INode*>& vectNode, T
{
// Result to return
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
CAnimation animFile;
@ -282,15 +297,48 @@ bool CNelExport::exportAnim (const char *sPath, std::vector<INode*>& vectNode, T
{
// Open a file
COFile file;
if (file.open (sPath))
if (file.open (tempFileName))
{
try
{
nldebug("Serialize the animation");
// Serial the animation
animFile.serial (file);
// Close the file
file.close();
// All is good
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)
{
@ -305,9 +353,31 @@ bool CNelExport::exportAnim (const char *sPath, std::vector<INode*>& vectNode, T
if (_ErrorInDialog)
MessageBox (NULL, "Can't open the file for writing.", "NeL export", MB_OK|MB_ICONEXCLAMATION);
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;
}

View file

@ -945,10 +945,7 @@ protected:
/// Put the string into the file.
virtual void doDisplay( const CLog::TDisplayInfo& args, const char *message )
{
DWORD ec = 0;
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId());
GetExitCodeProcess(h, &ec);
TerminateProcess(h, ec);
nelExportTerminateProcess();
}
};
@ -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.
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
putenv("NEL_IGNORE_ASSERT=1");
theCNelExport._ErrorInDialog = false;
theCNelExport._TerminateOnFileOpenIssues = true;
if (NLMISC::DefaultMsgBoxDisplayer || INelContext::getInstance().getDefaultMsgBoxDisplayer())
{
if (!NLMISC::DefaultMsgBoxDisplayer)
@ -978,10 +977,7 @@ Value* force_quit_right_now_cf(Value** arg_list, int count)
{
// because quitMAX can fail
nlwarning("Force quit");
DWORD ec = 0;
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId());
GetExitCodeProcess(h, &ec);
TerminateProcess(h, ec);
nelExportTerminateProcess();
return &true_value;
}