dont destroy buffers until not used

This commit is contained in:
Tyler Murphy 2022-09-28 10:51:15 -04:00
parent 9d0262e8a2
commit 50bd5c1a7e
5 changed files with 7 additions and 6 deletions

View file

@ -53,6 +53,7 @@ void Model::deleteModel(Model* model) {
void Model::submitDeleteQueue(bool purge) { void Model::submitDeleteQueue(bool purge) {
for(Model* model: DELETION_QUEUE) { for(Model* model: DELETION_QUEUE) {
vkDeviceWaitIdle(model->xeDevice.device());
try { delete model; } catch(int err) {}; try { delete model; } catch(int err) {};
} }
DELETION_QUEUE.clear(); DELETION_QUEUE.clear();

View file

@ -59,7 +59,7 @@ void Renderer::freeCommandBuffers() {
} }
VkCommandBuffer Renderer::beginFrame() { VkCommandBuffer Renderer::beginFrame() {
assert(!isFrameStarted && "Can't acll beingFrame while already in progress"); assert(!isFrameStarted && "Can't call beingFrame while already in progress");
auto result = xeSwapChain->acquireNextImage(&currentImageIndex); auto result = xeSwapChain->acquireNextImage(&currentImageIndex);

View file

@ -109,8 +109,6 @@ VkResult SwapChain::submitCommandBuffers(
submitInfo.signalSemaphoreCount = 1; submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores; submitInfo.pSignalSemaphores = signalSemaphores;
vkResetFences(device.device(), 1, &inFlightFences[currentFrame]); vkResetFences(device.device(), 1, &inFlightFences[currentFrame]);
if (vkQueueSubmit(device.graphicsQueue(), 1, &submitInfo, inFlightFences[currentFrame]) != if (vkQueueSubmit(device.graphicsQueue(), 1, &submitInfo, inFlightFences[currentFrame]) !=
VK_SUCCESS) { VK_SUCCESS) {

View file

@ -19,6 +19,8 @@ Chunk::~Chunk() {
if(worker.joinable()) if(worker.joinable())
worker.join(); worker.join();
xe::Model::deleteModel(chunkMesh); xe::Model::deleteModel(chunkMesh);
vertexData.data.clear();
cubes.clear();
} }
// //
@ -216,7 +218,7 @@ void Chunk::generate() {
for(int x = 0; x < 16; x++) { for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) { for(int z = 0; z < 16; z++) {
int height = perlin.octave2D_01((( x + gridX * 16) * 0.01), ((z + gridZ * 16) * 0.01), 4) * 10; int height = perlin.octave2D_01((( x + gridX * 16) * 0.01), ((z + gridZ * 16) * 0.01), 4) * 20;
for(int y = 0; y < 256; y++) { for(int y = 0; y < 256; y++) {
if(y == height){ if(y == height){
setBlock(x, y, z, GRASS); setBlock(x, y, z, GRASS);

View file

@ -73,8 +73,8 @@ void FirstApp::reloadLoadedChunks(xe::GameObject& viewer) {
int gridZ = static_cast<int>(floor(gameObject.transform.translation.z / 16.f)); int gridZ = static_cast<int>(floor(gameObject.transform.translation.z / 16.f));
int newGridX = minX + x; int newGridX = minX + x;
int newGridZ = minZ + z; int newGridZ = minZ + z;
// if(gridX < minX || gridZ < minZ || gridX > maxX || gridZ > maxZ) if(gridX < minX || gridZ < minZ || gridX > maxX || gridZ > maxZ)
// Chunk::deleteChunk(gridX, gridZ); Chunk::deleteChunk(gridX, gridZ);
Chunk* chunk = Chunk::getChunk(newGridX, newGridZ); Chunk* chunk = Chunk::getChunk(newGridX, newGridZ);
if(chunk == nullptr) { if(chunk == nullptr) {
chunk = Chunk::newChunk(newGridX, newGridZ, 12345); chunk = Chunk::newChunk(newGridX, newGridZ, 12345);