Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
vietanhdev committed Jul 29, 2023
1 parent 8d24ce4 commit c5c4fbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion customchar/audio/speech_recognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ std::string SpeechRecognizer::Transcribe(const std::vector<float>& pcmf32,
const int n_segments = whisper_full_n_segments(context_);
for (int i = 0; i < n_segments; ++i) {
const char* text = whisper_full_get_segment_text(context_, i);

result += text;

const int n_tokens = whisper_full_n_tokens(context_, i);
Expand Down
2 changes: 1 addition & 1 deletion customchar/audio/voice_synthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using namespace CC::audio;

VoiceSynthesizer::VoiceSynthesizer() {
// Check if the Say command is supported
std::string command = "Say --version";
std::string command = "which say";
FILE* pipe = popen(command.c_str(), "r");
if (pipe == nullptr) {
printf("Failed to run command: %s\n", command.c_str());
Expand Down
18 changes: 10 additions & 8 deletions customchar/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ void runImgui(std::shared_ptr<session::ChatHistory> history) {
// Initial text
char text[TEXT_MESSAGE_SIZE] = "";

GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

// Main loop
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
Expand Down Expand Up @@ -162,12 +169,7 @@ void runImgui(std::shared_ptr<session::ChatHistory> history) {
cv::resize(image, resized_image, cv::Size(new_width, new_height));
cv::cvtColor(resized_image, resized_image, cv::COLOR_BGR2RGBA);

GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
// Display image
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, resized_image.cols,
resized_image.rows, 0, GL_RGBA, GL_UNSIGNED_BYTE,
resized_image.data);
Expand Down Expand Up @@ -227,6 +229,7 @@ void runImgui(std::shared_ptr<session::ChatHistory> history) {

// Put the cursor of InputTextMultiline at the end of the text
ImGui::SetKeyboardFocusHere();
ImGui::End();

// Rendering
ImGui::Render();
Expand All @@ -241,8 +244,7 @@ void runImgui(std::shared_ptr<session::ChatHistory> history) {
glfwSwapBuffers(window);
}

std::cout << "Main ImGUI loop ended" << std::endl;

glDeleteTextures(1, &texture);
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
Expand Down

0 comments on commit c5c4fbc

Please sign in to comment.