Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About types #4

Open
sleeplessai opened this issue Aug 2, 2023 · 1 comment
Open

About types #4

sleeplessai opened this issue Aug 2, 2023 · 1 comment

Comments

@sleeplessai
Copy link

void checkFeatures(wgpu::Adapter adapter) {
    std::vector<wgpu::FeatureName> features;
    size_t featureCount = adapter.enumerateFeatures(nullptr);
    features.resize(featureCount);    /// <<<< HERE comes the error from clangd

    adapter.enumerateFeatures(features.data());

    for (auto feat : features) {
        std::clog << " - " << feat << '\n';
    }
}

I got the error hint about the wgpu::FeatureName default consturctor warning from clangd

In template: no matching function for call to 'construct_at'clang(ovl_no_viable_function_in_call)
stl_construct.h(115, 4): Error occurred here
stl_uninitialized.h(643, 8): In instantiation of function template specialization 'std::_Construct<wgpu::FeatureName>' requested here
stl_uninitialized.h(701, 4): In instantiation of function template specialization 'std::__uninitialized_default_n_1<false>::__uninit_default_n<wgpu::FeatureName *, unsigned long>' requested here
stl_uninitialized.h(779, 19): In instantiation of function template specialization 'std::__uninitialized_default_n<wgpu::FeatureName *, unsigned long>' requested here
vector.tcc(650, 8): In instantiation of function template specialization 'std::__uninitialized_default_n_a<wgpu::FeatureName *, unsigned long, wgpu::FeatureName>' requested here
stl_vector.h(1013, 4): In instantiation of member function 'std::vector<wgpu::FeatureName>::_M_default_append' requested here
adapter.cpp(18, 14): In instantiation of member function 'std::vector<wgpu::FeatureName>::resize' requested here
stl_construct.h(94, 5): Candidate template ignored: substitution failure [with _Tp = wgpu::FeatureName, _Args = <>]: no matching constructor for initialization of 'wgpu::FeatureName'

which makes me unable to use pure C++ binding in an elegant manner.
So I had to call the mixed like this:

void checkFeatures(wgpu::Adapter adapter) {
    std::vector<WGPUFeatureName> features;      //// <<< Use C-type WGPUFeatureName
    size_t featureCount = adapter.enumerateFeatures(nullptr);
    features.resize(featureCount);

    wgpuAdapterEnumerateFeatures(adapter, features.data());    ///<<< C API

    for (auto feat : features) {
        std::clog << " - " << feat << '\n';
    }
}

I am not sure if I could use the C++ bindings to finish your nice tutorials.
Here is another similar problem on type of wgpu::Surface and glfw3webgpu extension.
So I had to use type casting although it works:

wgpu::Surface surface = static_cast<wgpu::Surface>(glfwGetWGPUSurface(instance, window)); 

Please give me some advices on using C or C++ ? Thank you.

@eliemichel
Copy link
Owner

I'll have a look at this, I should find a way to make clang happy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants