Skip to content

Commit

Permalink
[emapp] activate model plugin on model editing mode (#98)
Browse files Browse the repository at this point in the history
* [plugin] fix incorrect delete operator detected by ASAN

* [emapp] prefer to use string instead of pointer

This change fixes a memory error detected by ASAN due to override of
model data by destroying and loading model data in
`ModelIOPluginProxy::execute` method.

The change also adds `Project::rebuildAllTracks` call to fix
memory error detected by ASAN due to change of `ITrack::opaque`
for the reason mentioned above.

* [emapp] activate model plugin menu on editing model mode

* [docs] update changelog
  • Loading branch information
hkrn authored Jan 18, 2022
1 parent 4292220 commit 8cda979
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
5 changes: 5 additions & 0 deletions docs/change_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
34.3.0 (未リリース)
******************************************

仕様変更
==========================================

* モデルプラグインをモデル編集においても利用可能になるようにした

不具合修正
==========================================

Expand Down
4 changes: 2 additions & 2 deletions emapp/include/emapp/internal/imgui/ModelParameterDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ModelParameterDialog : public BaseNonModalDialogWindow {
public:
struct SavedState {
struct ModelState {
const nanoem_model_bone_t *m_activeBone;
const nanoem_model_morph_t *m_activeMorph;
String m_activeBoneName;
String m_activeMorphName;
ByteArray m_modelData;
ByteArray m_motionData;
char m_datetime[32];
Expand Down
6 changes: 3 additions & 3 deletions emapp/plugins/ssb/ssb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1212,13 +1212,13 @@ SemiStandardBonePlugin::serializeUIComponentList()
nanoem__application__plugin__uiwindow__pack(&window, m_windowLayoutData.data());
{
delete[] globalComponents[0]->child_window->components;
delete globalComponents[0]->child_window->id;
delete[] globalComponents[0]->child_window->id;
delete globalComponents[0]->child_window;
delete globalComponents[0];
delete globalComponents[1]->same_line;
delete globalComponents[1];
delete[] globalComponents[2]->child_window->components;
delete globalComponents[2]->child_window->id;
delete[] globalComponents[2]->child_window->id;
delete globalComponents[2]->child_window;
delete globalComponents[2];
}
Expand Down Expand Up @@ -1253,7 +1253,7 @@ SemiStandardBonePlugin::destroyUIComponent(Nanoem__Application__Plugin__UICompon
for (size_t i = 0, numItems = value->child_window->n_components; i < numItems; i++) {
destroyUIComponent(value->child_window->components[i]);
}
delete value->child_window->id;
delete[] value->child_window->id;
delete value->child_window;
break;
}
Expand Down
1 change: 0 additions & 1 deletion emapp/src/ApplicationMenuBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,6 @@ ApplicationMenuBuilder::handleToggleModelEditingEnabledEvent(void *userData, boo
self->setMenuItemEnable(kMenuItemTypeEditMorphRemoveAllEyeKeyframes, invert);
self->setMenuItemEnable(kMenuItemTypeEditMorphRemoveAllEyebrowKeyframes, invert);
self->setMenuItemEnable(kMenuItemTypeEditMorphRemoveAllLipKeyframes, invert);
self->setMenuItemEnable(kMenuItemTypeEditModelPluginTitle, invert);
self->setMenuItemEnable(kMenuItemTypeEditMotionPluginTitle, invert);
self->setMenuItemEnable(kMenuItemTypeModelRemoveAllSelectedKeyframes, invert);
self->setMenuItemEnable(kMenuItemTypeCameraRegisterKeyframe, invert);
Expand Down
17 changes: 13 additions & 4 deletions emapp/src/internal/imgui/ModelParameterDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,12 @@ DisableModelEditingCommand::execute(Project *project)
it != end; ++it) {
const ModelParameterDialog::SavedState::ModelState &state = it->second;
Model *model = it->first;
model->setActiveBone(state.m_activeBone);
model->setActiveMorph(state.m_activeMorph);
if (const nanoem_model_bone_t *activeBonePtr = model->findBone(state.m_activeBoneName)) {
model->setActiveBone(activeBonePtr);
}
if (const nanoem_model_morph_t *activeMorphPtr = model->findMorph(state.m_activeMorphName)) {
model->setActiveMorph(activeMorphPtr);
}
saveLastModel(model, state, error);
if (Motion *motion = project->resolveMotion(model)) {
motion->load(state.m_motionData, 0, error);
Expand All @@ -795,6 +799,7 @@ DisableModelEditingCommand::execute(Project *project)
activeModel->restoreBindPose(m_state->m_bindPose);
project->restoreState(m_state->m_state, true);
project->destroyState(m_state->m_state);
project->rebuildAllTracks();
project->setEditingMode(m_state->m_lastEditingMode);
project->setModelEditingEnabled(false);
saveCurrentModel(activeModel, error);
Expand Down Expand Up @@ -7553,8 +7558,12 @@ ModelParameterDialog::setActiveModel(Model *model, Project *project)
if (!error.hasReason() &&
motion->save(state.m_motionData, model, NANOEM_MUTABLE_MOTION_KEYFRAME_TYPE_ALL, error)) {
motion->clearAllKeyframes();
state.m_activeBone = model->activeBone();
state.m_activeMorph = model->activeMorph();
if (const model::Bone *activeBone = model::Bone::cast(model->activeBone())) {
state.m_activeBoneName = activeBone->name();
}
if (const model::Morph *activeMorph = model::Morph::cast(model->activeMorph())) {
state.m_activeMorphName = activeMorph->name();
}
StringUtils::formatDateTimeLocal(state.m_datetime, sizeof(state.m_datetime), "%Y%m%d_%H%M%S");
m_savedState->m_modelStates.insert(tinystl::make_pair(model, state));
}
Expand Down

0 comments on commit 8cda979

Please sign in to comment.