microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.55k stars 1.57k forks source link

C/C++ Intellisense crashes on my template code. #7349

Closed rlj1202 closed 3 years ago

rlj1202 commented 3 years ago

Bug type: Language Service

Describe the bug

Steps to reproduce

Create cpp file and copy-paste following code occurs the error.

Expected behavior

After I removed following code, intellisense works perfectly.

Code sample and logs

template class _Mesh { private: template class GLType { public: static const unsigned int value; };

template<>
class GLType<float> { public: static const unsigned int value = GL_FLOAT; };
template<>
class GLType<int> { public: static const unsigned int value = GL_INT; };

template<typename... Ts>
class VboIter {
public:
    void CreateVbos(int loc);
    void DeleteVbos();
};

template<>
class VboIter<> {
public:
    void CreateVbos(int loc) {}
    void DeleteVbos() {}
};

template<typename DataType, int... Ptrs, typename... Rests>
class VboIter<Vbo<DataType, Ptrs...>, Rests...> : public VboIter<Rests...> {
public:
    template<typename Type, typename... Types>
    void CreateVbos(int loc, Type data, Types... rests) {
        glGenBuffers(1, &vbo_id);
        glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
        glBufferData(GL_ARRAY_BUFFER, sizeof(DataType) * data.size(), (void*) &data[0], GL_STATIC_DRAW);

        IteratePtrs(loc, 0, Ptrs...);

        VboIter<Rests...>::CreateVbos(loc + sizeof...(Ptrs), rests...);
    }

    void DeleteVbos() {
        glDeleteBuffers(1, &vbo_id);

        VboIter<Rests...>::DeleteVbos();
    }

    void CreatePtr(int loc, int offset, int size) {
        unsigned int type = GLType<DataType>::value;
        int total = (Ptrs + ...);

        glVertexAttribPointer(
            loc, size, type, GL_FALSE,
            sizeof(DataType) * total, (void*) (sizeof(DataType) * offset)
        );
        glEnableVertexAttribArray(loc);

        DEBUG_STDOUT("Set vertex pointer : loc = %d, offset = %d, size = %d\n", loc, offset, size);
    }

    void IteratePtrs(int loc, int offset, int size) {
        CreatePtr(loc, offset, size);
    }

    void IteratePtrs(int loc, int offset, int size, int rests...) {
        CreatePtr(loc, offset, size);

        IteratePtrs(loc + 1, offset + size, rests);
    }

    unsigned int vbo_id;
};

public: template _Mesh(std::vector indices, Types... data) { glGenVertexArrays(1, &vao_id); glBindVertexArray(vao_id);

    vbo_iter.CreateVbos(0, data...);

    glGenBuffers(1, &ebo_id);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_id);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indices.size(), (void*) &indices[0], GL_STATIC_DRAW);

    cnt_vertices = indices.size();

    glBindVertexArray(0);
}
~_Mesh() {
    if (vao_id) {
        glDeleteVertexArrays(1, &vao_id);
    }
    vbo_iter.DeleteVbos();
    if (ebo_id) {
        glDeleteBuffers(1, &ebo_id);
    }
}

void Bind() {
    glBindVertexArray(vao_id);
}

void Draw() {
    glDrawElements(GL_TRIANGLES, cnt_vertices, GL_UNSIGNED_INT, (void*) 0);
}

private: unsigned int vao_id; unsigned int ebo_id; unsigned int cnt_vertices;

VboIter<Vbos...> vbo_iter;

};

- Configurations in `c_cpp_properties.json`
```json
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "EMSCRIPTEN"
            ],
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json",
            "configurationProvider": "ms-vscode.cmake-tools",
            "browse": {
                "path": [
                    "/usr/include",
                    "/workspaces/codespace/emscripten/system/include"
                ]
            }
        }
    ],
    "version": 4
}

Screenshots

screenshot

Additional context

Regardless the GL header file is not include, the problem occurs in a same manner. I remember that the code was intellisensed before correctly but at some point, this thing have been happened.

If there is anything I need to provide, I am willing to do so.

sean-mcmanus commented 3 years ago

Thanks for reporting this. I've filed a bug on our shared VS parser at https://developercommunity.visualstudio.com/t/C-IntelliSense-processes-crashing-when/1397318

sean-mcmanus commented 3 years ago

Looks like it's being tracked by https://developercommunity.visualstudio.com/t/Broken-intellisense-with-template-specia/1359157 now.

Colengms commented 3 years ago

This should be addressed in 1.6.0-insiders.