FPS degrades over time when implementing DebugRendererSimple using OpenGL. #1183
-
This problem is mostly C++ and OpenGL related than Jolt related, so I am sorry if it is not appropriate to ask here. Here is my implementation: std::vector<std::array<float, 9>> triangleQueue;
class TestDebugRenderer : public DebugRendererSimple {
public:
virtual void DrawLine(RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor) override {}
virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor, ECastShadow inCastShadow) override {
std::array<float, 9> triangle {};
triangle[0] = inV1.GetX();
triangle[1] = inV1.GetY();
triangle[2] = inV1.GetZ();
triangle[3] = inV2.GetX();
triangle[4] = inV2.GetY();
triangle[5] = inV2.GetZ();
triangle[6] = inV3.GetX();
triangle[7] = inV3.GetY();
triangle[8] = inV3.GetZ();
triangleQueue.push_back(triangle);
}
virtual void DrawText3D(RVec3Arg inPosition, const std::string_view& inString, ColorArg inColor, float inHeight) override {}
}; And in the render() function: if (isPhysicsRunning == true && !triangleQueue.empty()) {
for (std::array<float, 9> &triangle : triangleQueue) {
glm::mat4 model = glm::mat4(1.0f);
model = glm::scale(model, glm::vec3(0.5));
unsigned int modelLoc = glGetUniformLocation(shader.ID, "model");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
unsigned int VBO, VAO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(triangle), triangle.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
shader.use();
glDrawArrays(GL_TRIANGLES, 0, 3);
}
}
triangleQueue.clear(); And the context of where DrawBodies and render are called: while(isRunning) {
if (isPhysicsRunning) {
[other Jolt and OpenGL code here]
BodyManager::DrawSettings drawSettings;
drawSettings.mDrawShape = true;
drawSettings.mDrawBoundingBox = true;
drawSettings.mDrawCenterOfMassTransform = true;
drawSettings.mDrawWorldTransform = true;
physics_system.DrawBodies(drawSettings, &debugRenderer);
physics_system.Update(deltaTime, cCollisionSteps, &temp_allocator, &job_system);
}
render(shader, &skybox, skyboxShader, io);
} Here is a video of this happening: The more you leave it running the worse it gets: This is most likely a memory leak, But I do not know how to fix it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Because I using new VAO and VBO's and not deleting them. |
Beta Was this translation helpful? Give feedback.
Because I using new VAO and VBO's and not deleting them.
Now when I started using the same VAO and VBO then editing them the issue is gone.