使用VSTGUI編寫新的vst-plugin我真的很困難如何使用庫,並且大部分進度都是在猜測和調試之後完成的(因爲那裏除了百萬行和ygrabit之外,其實沒有任何文檔,只是顯而易見)。VSTGUI:編輯約定::打開和編輯::關閉
到目前爲止,這樣做還不錯,但是我對該項目的最後一個貢獻涉及到線程,這使得設計更加有問題。具體來說,我正在處理容器中的一組文本標記(執行非原子操作),並且在用戶關閉窗口時,這些可能(顯然確實)在我不知情的情況下被破壞。 即使在更改元素之前添加檢查可能仍然是一個問題。所以我實際上需要控制這些對象的生命週期(這很好),除非它們顯示在CViewContainer中,它會自動承擔所有權。
我不知道如何編寫編輯器的主幹,所以我使用了一個名爲VSTGUIBuilder的程序,並附加(並基本上重寫了)我需要的東西。但是,由於您可以使用的所有「視圖」都需要父級或系統窗口,因此在到達AEffEditor :: Open()函數之前無法實例化任何視圖/控件,每當您彈出窗口時都會調用該函數。 只要窗口關閉,就調用AEffEditor :: close()方法。現在,vstguibuilder把
delete frame;
這表明你重建和分配上的每個打開和關閉所有資源AEffEditor :: close()方法中。這真的可以嗎?如果是這樣,我有沒有辦法保護我的容器的內容(詳細信息是一個向量< CTextLabel *>)被刪除的中間函數?之後處理它不成問題,我只是在改變它的同時擔心段錯誤。
使用互斥鎖,這真的是最後的手段(如果來自主機的呼叫),我不想在任何情況下掛起主機,如果我的代碼出現故障並從不發佈。
編輯: 我最終找到了一個不太優雅但安全工作的解決方案。下面是工人函數的代碼:
while(bLock) {
Sleep(0);
}
bLock = true;
if(msgs.empty())
return;
/*
Prevent someone deletes our lines in close().
we create a copy of the container to be 100% sure
and increase the reference count, so we can safely
work with our own container and we 'forget' them
afterwards, so they will be deleted if needed.
This ensures that close AND open can be called
meanwhile we are working with the lines
*/
bDeleteLock = true;
// also the copy constructor should work as expected here
// since we are working with pointers, we still reference the same content.
auto copy_lines = lines;
for each(auto line in copy_lines) {
line->remember();
}
bDeleteLock = false;
...
for each(auto line in copy_lines) {
line->forget();
}
cont->setDirty();
塊是另一種「互斥」保護消息隊列,此功能將打印出來。 bDeleteLock保護複製行容器並「記住」它們的過程,並在以後立即釋放。兩者都被宣佈爲不穩定的布爾人,應該不夠嗎?這裏是close()方法。
void CConsole::Close() {
// locking lines while copying them over in a container we can work with
while(bDeleteLock)
Sleep(0);
//waiting for bLock is not needed because it wont get deleted.
if(!visible) //if we are not visible it's our responsibility to remove the view
delete cont;
lines.clear();
}
是..我打賭它。是的,我最終鎖定了一個基本互斥鎖的數據,你可以看到發佈的解決方案。我真的覺得實例化很奇怪,但我想這是一種在窗口未打開的情況下節省內存的方式(以打開時處理能力爲代價)。 – Shaggi