some fixes (less crashing)

Originally committed to SVN as r907.
This commit is contained in:
pomyk 2007-01-29 21:25:13 +00:00
parent 614758ac6c
commit dee1c6760e
3 changed files with 32 additions and 13 deletions

View file

@ -457,8 +457,7 @@ namespace Automation4 {
{ {
wxString _m(StringValueCStr(msg), wxConvUTF8); wxString _m(StringValueCStr(msg), wxConvUTF8);
RubyProgressSink::inst->AddDebugOutput(_m); RubyProgressSink::inst->AddDebugOutput(_m);
RubyProgressSink::inst->Refresh(); RubyProgressSink::inst->DoUpdateDisplay();
RubyProgressSink::inst->Update();
return Qtrue; return Qtrue;
} }
@ -568,7 +567,9 @@ namespace Automation4 {
return rb_funcall2(a.recv, a.id, a.n, a.argv); return rb_funcall2(a.recv, a.id, a.n, a.argv);
} }
VALUE rbExecWrapper(VALUE arg){return ruby_exec();} VALUE rbExecWrapper(VALUE arg){return ruby_exec();}
VALUE rbLoadWrapper(VALUE arg){rb_load(/*reinterpret_cast<const char*>*/(arg), 0); return Qtrue;} VALUE rbLoadWrapper(VALUE arg){rb_load(arg, 0); return Qtrue;}
VALUE rbAss2RbWrapper(VALUE arg){return RubyAssFile::AssEntryToRuby(reinterpret_cast<AssEntry*>(arg));}
VALUE rb2AssWrapper(VALUE arg){return reinterpret_cast<VALUE>(RubyAssFile::RubyToAssEntry(arg));}
VALUE rbFunCall(VALUE recv, ID id, int n, ...) VALUE rbFunCall(VALUE recv, ID id, int n, ...)
{ {

View file

@ -251,8 +251,10 @@ namespace Automation4 {
VALUE rbExecWrapper(VALUE arg); VALUE rbExecWrapper(VALUE arg);
VALUE rbLoadWrapper(VALUE arg); VALUE rbLoadWrapper(VALUE arg);
VALUE rbFunCall(VALUE recv, ID id, int n, ...); VALUE rbFunCall(VALUE recv, ID id, int n, ...);
VALUE rbAss2RbWrapper(VALUE arg);
VALUE rb2AssWrapper(VALUE arg);
typedef VALUE (*RB_HOOK)(...); typedef VALUE (*RB_HOOK)(...);
typedef VALUE (*RB_HOOK2)(void*); typedef VALUE (*RB_HOOK2)(VALUE);
}; };

View file

@ -94,7 +94,7 @@ namespace Automation4 {
} else if (e->GetType() == ENTRY_DIALOGUE) { } else if (e->GetType() == ENTRY_DIALOGUE) {
AssDialogue *dia = e->GetAsDialogue(e); AssDialogue *dia = e->GetAsDialogue(e);
rb_hash_aset(ass_entry, rb_str_new2("comment"), rb_int2inum((int)dia->Comment)); rb_hash_aset(ass_entry, rb_str_new2("comment"), dia->Comment ? Qtrue : Qfalse);
rb_hash_aset(ass_entry, rb_str_new2("layer"), rb_int2inum(dia->Layer)); rb_hash_aset(ass_entry, rb_str_new2("layer"), rb_int2inum(dia->Layer));
rb_hash_aset(ass_entry, rb_str_new2("start_time"), rb_int2inum(dia->Start.GetMS())); rb_hash_aset(ass_entry, rb_str_new2("start_time"), rb_int2inum(dia->Start.GetMS()));
rb_hash_aset(ass_entry, rb_str_new2("end_time"), rb_int2inum(dia->End.GetMS())); rb_hash_aset(ass_entry, rb_str_new2("end_time"), rb_int2inum(dia->End.GetMS()));
@ -290,7 +290,7 @@ namespace Automation4 {
} else if (lclass == _T("dialogue")) { } else if (lclass == _T("dialogue")) {
VALUE _comment = rb_hash_aref(ass_entry, rb_str_new2("comment")); VALUE _comment = rb_hash_aref(ass_entry, rb_str_new2("comment"));
bool comment = (bool)rb_num2long(_comment); bool comment = _comment == Qfalse ? false : true;
VALUE _layer = rb_hash_aref(ass_entry, rb_str_new2("layer")); VALUE _layer = rb_hash_aref(ass_entry, rb_str_new2("layer"));
int layer = rb_num2long(_layer); int layer = rb_num2long(_layer);
VALUE _start_time = rb_hash_aref(ass_entry, rb_str_new2("start_time")); VALUE _start_time = rb_hash_aref(ass_entry, rb_str_new2("start_time"));
@ -349,8 +349,15 @@ namespace Automation4 {
if(size <= 0) return; // empty - leave the original if(size <= 0) return; // empty - leave the original
VALUE rbEntry = rb_ary_shift(subtitles); VALUE rbEntry;
AssEntry *new_entry = RubyToAssEntry(rbEntry); AssEntry* new_entry;
int status = 0;
do {
rbEntry = rb_ary_shift(subtitles);
new_entry = reinterpret_cast<AssEntry*>(rb_protect(rb2AssWrapper, rbEntry, &status));
--size;
}while(status != 0); // broken lines at the beginning?
ruby_errinfo = Qnil; // just in case
entryIter e = ass->Line.begin(); entryIter e = ass->Line.begin();
if(new_entry->GetType() == ENTRY_DIALOGUE) // check if the first line is a dialogue if(new_entry->GetType() == ENTRY_DIALOGUE) // check if the first line is a dialogue
@ -363,11 +370,15 @@ namespace Automation4 {
e = ass->Line.erase(e); e = ass->Line.erase(e);
} }
ass->Line.push_back(new_entry); ass->Line.push_back(new_entry);
for(int i = 1; i < size; i++) // insert new lines for(int i = 0; i < size; i++) // insert new lines
{ {
rbEntry = rb_ary_shift(subtitles); rbEntry = rb_ary_shift(subtitles);
new_entry = RubyToAssEntry(rbEntry); new_entry = reinterpret_cast<AssEntry*>(rb_protect(rb2AssWrapper, rbEntry, &status));
ass->Line.push_back(new_entry); if(status == 0) ass->Line.push_back(new_entry);
else {
// TODO: log/display the error
ruby_errinfo = Qnil; // clear the error
}
} }
RubyObjects::Get()->Unregister(subtitles); RubyObjects::Get()->Unregister(subtitles);
} }
@ -549,9 +560,14 @@ namespace Automation4 {
RubyObjects::Get()->Register(rbAssFile); RubyObjects::Get()->Register(rbAssFile);
std::list<AssEntry*>::iterator entry; std::list<AssEntry*>::iterator entry;
int status;
for(entry = ass->Line.begin(); entry != ass->Line.end(); ++entry) for(entry = ass->Line.begin(); entry != ass->Line.end(); ++entry)
{ {
rb_ary_push(rbAssFile, AssEntryToRuby(*entry)); VALUE res = rb_protect(rbAss2RbWrapper, reinterpret_cast<VALUE>(*entry), &status);
if(status == 0) rb_ary_push(rbAssFile, res);
else {
ruby_errinfo = Qnil;
}
} }
// TODO // TODO