Fixed crash related to the new keyframe system

Originally committed to SVN as r589.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-23 02:42:34 +00:00
parent d89e522fd4
commit 7cbab8cdfe
1 changed files with 57 additions and 34 deletions

View File

@ -985,13 +985,14 @@ void FrameMain::LoadVFR(wxString filename) {
VFR_Output.Load(filename); VFR_Output.Load(filename);
SubsBox->Refresh(false); SubsBox->Refresh(false);
} }
// Fail // Fail
catch (const wchar_t *error) { catch (const wchar_t *error) {
wxString err(error); wxString err(error);
wxMessageBox(err, _T("Error opening timecodes file"), wxOK | wxICON_ERROR, this); wxMessageBox(err, _T("Error opening timecodes file"), wxOK | wxICON_ERROR, this);
} }
catch (...) { catch (...) {
wxMessageBox(_T("Unknown error"), _T("Error opening video file"), wxOK | wxICON_ERROR, this); wxMessageBox(_T("Unknown error"), _T("Error opening timecodes file"), wxOK | wxICON_ERROR, this);
} }
} }
@ -1010,46 +1011,68 @@ void FrameMain::LoadVFR(wxString filename) {
////////////////// //////////////////
// Load Keyframes // Load Keyframes
void FrameMain::LoadKeyframes(wxString filename) { void FrameMain::LoadKeyframes(wxString filename) {
// Open file // Unload
wxArrayInt keyFrames; if (filename.IsEmpty()) {
keyFrames.Empty(); wxArrayInt keyFrames;
TextFileReader file(filename,_T("ASCII")); keyFrames.Empty();
videoBox->videoDisplay->SetOverKeyFrames(keyFrames);
videoBox->videoDisplay->SetKeyFramesName(filename);
Refresh();
}
// Read header // Load
wxString cur = file.ReadLineFromFile(); try {
if (cur != _T("# keyframe format v1")) return; // Open file
cur = file.ReadLineFromFile(); wxArrayInt keyFrames;
if (cur.Left(4) != _T("fps ")) return; keyFrames.Empty();
cur = cur.Mid(4); TextFileReader file(filename,_T("ASCII"));
double fps;
cur.ToDouble(&fps);
// Read lines // Read header
while (file.HasMoreLines()) { wxString cur = file.ReadLineFromFile();
if (cur != _T("# keyframe format v1")) _T("Invalid keyframes file.");
cur = file.ReadLineFromFile(); cur = file.ReadLineFromFile();
if (!cur.IsEmpty() && cur.IsNumber()) { if (cur.Left(4) != _T("fps ")) throw _T("Invalid keyframes file.");
long temp; cur = cur.Mid(4);
cur.ToLong(&temp); double fps;
keyFrames.Add(temp); cur.ToDouble(&fps);
if (fps == 0.0) throw _T("Invalid FPS.");
// Read lines
while (file.HasMoreLines()) {
cur = file.ReadLineFromFile();
if (!cur.IsEmpty() && cur.IsNumber()) {
long temp;
cur.ToLong(&temp);
keyFrames.Add(temp);
}
} }
// Set keyframes
videoBox->videoDisplay->SetOverKeyFrames(keyFrames);
videoBox->videoDisplay->SetKeyFramesName(filename);
// Set FPS
if (!videoBox->videoDisplay->loaded) {
videoBox->videoDisplay->fps = fps;
VFR_Input.SetCFR(fps);
if (!VFR_Output.IsLoaded()) VFR_Output.SetCFR(fps);
}
// Add to recent
Options.AddToRecentList(filename,_T("Recent keyframes"));
// Refresh display
Refresh();
} }
// Set keyframes // Fail
videoBox->videoDisplay->SetOverKeyFrames(keyFrames); catch (const wchar_t *error) {
videoBox->videoDisplay->SetKeyFramesName(filename); wxString err(error);
wxMessageBox(err, _T("Error opening keyframes file"), wxOK | wxICON_ERROR, this);
// Set FPS }
if (!videoBox->videoDisplay->loaded) { catch (...) {
videoBox->videoDisplay->fps = fps; wxMessageBox(_T("Unknown error"), _T("Error opening keyframes file"), wxOK | wxICON_ERROR, this);
VFR_Input.SetCFR(fps);
if (!VFR_Output.IsLoaded()) VFR_Output.SetCFR(fps);
} }
// Add to recent
Options.AddToRecentList(filename,_T("Recent keyframes"));
// Refresh display
Refresh();
} }