2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

"Assertion failed!" error while using CPlusPlus OP in TouchDesigner

Posted at

はじめに

TouchDesignerのCPlusPlus OPにはsetupParametersというメンバ関数を用いて,任意の変数をオペレータのプロパティに表示して実行時に変更することができる.
このメンバ関数の名前の指定に関して規則があり,試行錯誤が必要となったのでメモしておく.

変更前

速度の最大値としてFloat型のmaxVelという名前の変数をプロパティに表示したい.
.cppファイルのsetupParametersに以下の内容を記載した.

void
CPlusPlusDATExample::setupParameters(OP_ParameterManager* manager, void* reserved1)
{
	{
		OP_NumericParameter	

		np.name = "maxVel";
		np.label = "maxVel";
		np.defaultValues[0] = 1.0;
		np.minSliders[0] = -10.0;
		np.maxSliders[0] =  10.0;
		
		OP_ParAppendResult res = manager->appendFloat(np);
		assert(res == OP_ParAppendResult::Success);
	}
}

エラー内容

ビルドは上手くいくものの,デバッグなどのTouchDesigner実行時に以下のようなエラーメッセージがポップアップで表示される.
メッセージの内容としては,Expression: res == OP_ParAppendResult::SuccessでAssertion failedが発生したようで,どうやら.cppファイルのOP_ParAppendResult res = manager->appendFloat(np);が失敗していることが原因の様.

image.png

変更後

試行錯誤の結果,op.nameの名づけによってエラーが発生していることが分かった.
規則としては,一文字目のみを大文字のスペースを含まない文字列であればよいらしい.
変更前はC++を意識した変数名にしていたことがまずかったようだ.
また,np.labelにはルールは無いようで,任意の文字列でよいので視認性を重視して変更した.

void
CPlusPlusDATExample::setupParameters(OP_ParameterManager* manager, void* reserved1)
{

	// speed
	{
		OP_NumericParameter	np;

		np.name = "Maxvel";               // 一文字目のみ大文字
		np.label = "Maximum Velocity";    // 表記は自由
		np.defaultValues[0] = 1.0;
		np.minSliders[0] = -10.0;
		np.maxSliders[0] =  10.0;
		
		OP_ParAppendResult res = manager->appendFloat(np);
		assert(res == OP_ParAppendResult::Success);
	}
}

実行結果

np.nameの変更によって上記のエラーは回避できる.
実行結果として,変数の表示名としてnp.labelが,pythonで呼ぶ際の変数名として小文字のnp.nameが格納される.

image.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?