Skip to content

Commit c907cb8

Browse files
committed
Fix the crash bug in ecosystem_utilities.cpp and fix gltf_ktx to compile in Android again.
1 parent 3d53a37 commit c907cb8

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

attachments/32_ecosystem_utilities.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ class HelloTriangleApplication {
158158
std::vector<vk::raii::Fence> inFlightFences;
159159
vk::raii::Semaphore timelineSemaphore = nullptr;
160160
uint64_t timelineValue = 0;
161-
uint32_t semaphoreIndex = 0;
162161
uint32_t currentFrame = 0;
163162

164163
bool framebufferResized = false;
@@ -313,7 +312,7 @@ class HelloTriangleApplication {
313312
debugMessenger = instance.createDebugUtilsMessengerEXT(debugUtilsMessengerCreateInfoEXT);
314313
} catch (vk::SystemError& err) {
315314
// If the debug utils extension is not available, this will fail
316-
// That's okay, it just means validation layers aren't enabled
315+
// That's okay; it just means validation layers aren't enabled
317316
std::cout << "Debug messenger not available. Validation layers may not be enabled." << std::endl;
318317
}
319318
}
@@ -1300,9 +1299,6 @@ class HelloTriangleApplication {
13001299
std::array<vk::ClearValue, 2> clearValues = { clearColor, clearDepth };
13011300

13021301
if (appInfo.dynamicRenderingSupported) {
1303-
// Use dynamic rendering
1304-
std::cout << "Recording command buffer with dynamic rendering\n";
1305-
13061302
// Transition attachments to the correct layout
13071303
if (appInfo.synchronization2Supported) {
13081304
// Use Synchronization2 API for image transitions
@@ -1551,7 +1547,7 @@ class HelloTriangleApplication {
15511547
void drawFrame() {
15521548
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[currentFrame], vk::True, FenceTimeout))
15531549
;
1554-
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphore[semaphoreIndex], nullptr);
1550+
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphore[currentFrame], nullptr);
15551551

15561552
if (result == vk::Result::eErrorOutOfDateKHR) {
15571553
recreateSwapChain();
@@ -1577,11 +1573,11 @@ class HelloTriangleApplication {
15771573
.pSignalSemaphoreValues = &signalValue
15781574
};
15791575

1580-
std::array<vk::Semaphore, 2> waitSemaphores = { *presentCompleteSemaphore[semaphoreIndex], *timelineSemaphore };
1576+
std::array<vk::Semaphore, 2> waitSemaphores = { *presentCompleteSemaphore[currentFrame], *timelineSemaphore };
15811577
std::array<vk::PipelineStageFlags, 2> waitStages = { vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eVertexInput };
15821578
std::array<uint64_t, 2> waitValues = { 0, waitValue }; // Binary semaphore value is ignored
15831579

1584-
std::array<vk::Semaphore, 2> signalSemaphores = { *renderFinishedSemaphore[imageIndex], *timelineSemaphore };
1580+
std::array<vk::Semaphore, 2> signalSemaphores = { *renderFinishedSemaphore[currentFrame], *timelineSemaphore };
15851581
std::array<uint64_t, 2> signalValues = { 0, signalValue }; // Binary semaphore value is ignored
15861582

15871583
timelineInfo.waitSemaphoreValueCount = 1; // Only for the timeline semaphore
@@ -1606,19 +1602,19 @@ class HelloTriangleApplication {
16061602
vk::PipelineStageFlags waitDestinationStageMask(vk::PipelineStageFlagBits::eColorAttachmentOutput);
16071603
const vk::SubmitInfo submitInfo{
16081604
.waitSemaphoreCount = 1,
1609-
.pWaitSemaphores = &*presentCompleteSemaphore[semaphoreIndex],
1605+
.pWaitSemaphores = &*presentCompleteSemaphore[currentFrame],
16101606
.pWaitDstStageMask = &waitDestinationStageMask,
16111607
.commandBufferCount = 1,
16121608
.pCommandBuffers = &*commandBuffers[currentFrame],
16131609
.signalSemaphoreCount = 1,
1614-
.pSignalSemaphores = &*renderFinishedSemaphore[imageIndex]
1610+
.pSignalSemaphores = &*renderFinishedSemaphore[currentFrame]
16151611
};
16161612
graphicsQueue.submit(submitInfo, *inFlightFences[currentFrame]);
16171613
}
16181614

16191615
const vk::PresentInfoKHR presentInfoKHR{
16201616
.waitSemaphoreCount = 1,
1621-
.pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
1617+
.pWaitSemaphores = &*renderFinishedSemaphore[currentFrame],
16221618
.swapchainCount = 1,
16231619
.pSwapchains = &*swapChain,
16241620
.pImageIndices = &imageIndex
@@ -1630,7 +1626,6 @@ class HelloTriangleApplication {
16301626
} else if (result != vk::Result::eSuccess) {
16311627
throw std::runtime_error("failed to present swap chain image!");
16321628
}
1633-
semaphoreIndex = (semaphoreIndex + 1) % presentCompleteSemaphore.size();
16341629
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
16351630
}
16361631

attachments/35_gltf_ktx.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,19 @@ class VulkanApplication {
499499
);
500500
result = vk_result == static_cast<int>(vk::Result::eSuccess);
501501
#endif
502+
const char* name = nullptr;
503+
#ifdef PLATFORM_ANDROID
504+
name = profileProperties.name;
505+
#else
506+
name = profileProperties.profileName;
507+
#endif
502508

503509
if (result && supported == VK_TRUE) {
504510
appInfo.profileSupported = true;
505511
appInfo.profile = profileProperties;
506-
LOGI("Device supports Vulkan profile: %s", profileProperties.profileName);
512+
LOGI("Device supports Vulkan profile: %s", name);
507513
} else {
508-
LOGI("Device does not support Vulkan profile: %s", profileProperties.profileName);
514+
LOGI("Device does not support Vulkan profile: %s", name);
509515
}
510516
} else {
511517
throw std::runtime_error("failed to find a suitable GPU!");
@@ -1416,7 +1422,7 @@ class VulkanApplication {
14161422
#if PLATFORM_ANDROID
14171423
// Android asset loading
14181424
if (androidAppState.app == nullptr) {
1419-
LOG_ERROR("Android app not initialized");
1425+
LOGE("Android app not initialized");
14201426
throw std::runtime_error("Android app not initialized");
14211427
}
14221428
AAsset* asset = AAssetManager_open(androidAppState.app->activity->assetManager, filename.c_str(), AASSET_MODE_BUFFER);

0 commit comments

Comments
 (0)