Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Unable to create a function with parameter when Type.IsValueType is true

オープン
#174 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp, unity, wasm
領域
api

調査の方向性

src/Value.cs の Value.TryGetKind から始め、次に例外が報告される src/Function.cs の GetFunctionType と Function.FromCallback の周辺を調べてください。Vector3 と object のパラメーターを使用して Unity 2021.3 の externref サンプルを再現し、サポートされている動作とテストが UnityEngine.Vector3 のような値型を対象としているか確認してください。

索引モデルが issue の本文から書いたものです。

説明

I have a really simple adaption of the externref sample, running inside unity 2021.3, whose csharp runtime is ostensibly .NET standard 2.1 compatible:

(module
  (import "" "getX" (func $.getX (param externref) (result f32)))
  (func (export "run") (param externref) (result f32)
    local.get 0
    call $.getX
  )
)
public class WasmTest : MonoBehaviour
{
    public TextAsset watSource;

    void Start()
    {
        var engine = new Engine();

        var module = Module.FromText(
            engine,
            watSource.name,
            watSource.text
        );

        var linker = new Linker(engine);
        var store = new Store(engine);

        linker.Define(
            "",
            "getX",
            Function.FromCallback(store, (Vector3 vec) => ((Vector3)vec).x)
        );

        var instance = linker.Instantiate(store, module);
        var run = instance.GetFunction<object, float>("run");
        float res = run(transform.position);
        Debug.Log($"the x is {res}");
    }
}

However, as written, I get

WasmtimeException: Unable to create a function with parameter of type 'UnityEngine.Vector3'.
Wasmtime.Function.GetFunctionType (System.Type type, System.Boolean hasReturn, System.Collections.Generic.List`1[T] parameters, System.Collections.Generic.List`1[T] results, System.Boolean& hasCaller, System.Boolean& returnsTuple) (at C:/Users/s/source/repos/wasmtime-dotnet/src/Function.cs:2411)
Wasmtime.Function..ctor (Wasmtime.IStore store, System.Delegate callback, System.Boolean hasReturn) (at C:/Users/s/source/repos/wasmtime-dotnet/src/Function.cs:2242)
Wasmtime.Function.FromCallback[T,TResult] (Wasmtime.IStore store, System.Func`2[T,TResult] callback) (at C:/Users/s/source/repos/wasmtime-dotnet/src/Function.cs:300)
WasmTest.Start () (at Assets/wasmtest/WasmTest.cs:25)

If I change the function argument type from Vector3 to just object and do the cast manually, it works as expected. Looks like it's because it falls out of Value.TryGetKind at https://github.com/bytecodealliance/wasmtime-dotnet/blob/387edd242f105d5394399acd19c25509ebb42b02/src/Value.cs#L210 , because unity sets Type.IsValueType == true.

Is that test of IsValueType necessary? I don't know if this is just a weird unity environment thing.

主要言語
C#
スター
524
フォーク
71
平均マージ
17時間 26分
マージ済み PR(30日)
6

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bytecodealliance/wasmtime-dotnet のほかの issue

bytecodealliance/wasmtime-dotnet の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。