How to refresh the texture for DirectX12? #8096
KADGang
started this conversation in
New Users Build/Link/Run issues ONLY!
Replies: 1 comment 2 replies
-
|
I finally done it, I moved the code into my inner source file then it worked. Unbelievable 🤣 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on a feature similar to an image viewer: the user enters the path to an image and I render it on the screen. I looked at the sample code for this. I plugged it into my source file and it worked perfectly. But when I tried to load another image, it crashed. What should I do in this situation?
My code:
{ ImGui::Text("CPU handle = %p", my_texture_srv_cpu_handle.ptr); ImGui::Text("GPU handle = %p", my_texture_srv_gpu_handle.ptr); ImGui::Text("size = %d x %d", my_image_width, my_image_height); if (ImGui::Button("load9")) { if (my_texture != NULL) { DestroyTexture(&my_texture); my_image_width = 0; my_image_height = 0; } LoadTextureFromFile("9.png", g_pd3dDevice, my_texture_srv_cpu_handle, &my_texture, &my_image_width, &my_image_height); } ImGui::SameLine(); if (ImGui::Button("load8")) { if (my_texture != NULL) { DestroyTexture(&my_texture); my_image_width = 0; my_image_height = 0; } LoadTextureFromFile("chara_ram.png", g_pd3dDevice, my_texture_srv_cpu_handle, &my_texture, &my_image_width, &my_image_height); } ImGui::SameLine(); if (ImGui::Button("clear")) { if (my_texture != NULL) { my_texture_srv_gpu_handle = g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart(); my_texture_srv_gpu_handle.ptr += (handle_increment * descriptor_index); // DestroyTexture(&my_texture); my_image_width = 0; my_image_height = 0; } } // Note that we pass the GPU SRV handle here, *not* the CPU handle. We're passing the internal pointer value, cast to an ImTextureID ImGui::Image((ImTextureID)my_texture_srv_gpu_handle.ptr, ImVec2((float)my_image_width, (float)my_image_height)); }I set three buttons in the window, for the first one and the second one, if you click it then it will load a image file for a texture.
It works very well at first time to load a image:
But when I click the button twice, it crashed.
Could you tell me how to implement this function correctly?
Beta Was this translation helpful? Give feedback.
All reactions