Skip to content

Commit

Permalink
Fix: 空の辞書でクラッシュするバグを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Jan 26, 2024
1 parent 4e13bca commit c509263
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/voicevox_core/src/engine/open_jtalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ pub(crate) mod blocking {
}

impl Inner {
// FIXME: 中断可能にする
// TODO: 中断可能にする
pub(super) fn unload_user_dict(&self) -> crate::result::Result<()> {
let Resources { mecab, .. } = &mut *self.resources.lock().unwrap();
mecab.load_with_userdic(&self.dict_dir, None)
}

// TODO: 中断可能にする
pub(super) fn use_user_dict(&self, words: &str) -> crate::result::Result<()> {
let result = {
// ユーザー辞書用のcsvを作成
Expand Down Expand Up @@ -210,6 +216,9 @@ pub(crate) mod tokio {
user_dict: &crate::tokio::UserDict,
) -> crate::result::Result<()> {
let inner = self.0 .0.clone();
if user_dict.is_empty() {
return crate::task::asyncify(move || inner.unload_user_dict()).await;
}
let words = user_dict.to_mecab_format();
crate::task::asyncify(move || inner.use_user_dict(&words)).await
}
Expand Down
10 changes: 10 additions & 0 deletions crates/voicevox_core/src/user_dict/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ pub(crate) mod blocking {
"\n",
)
}

/// ユーザー辞書が空かどうかを返す。
pub(crate) fn is_empty(&self) -> bool {
self.words.lock().unwrap().is_empty()
}
}
}

Expand Down Expand Up @@ -174,5 +179,10 @@ pub(crate) mod tokio {
pub(crate) fn to_mecab_format(&self) -> String {
self.0.to_mecab_format()
}

/// ユーザー辞書が空かどうかを返す。
pub(crate) fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
}

0 comments on commit c509263

Please sign in to comment.