Skip to content

Commit

Permalink
Refactored CC_ASSERT to require a semicolon at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
Raelr committed Jul 28, 2022
1 parent ea6696c commit 4c7217d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 24 deletions.
21 changes: 6 additions & 15 deletions engine/render/renderer/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,13 @@ typedef uint64_t u64;
typedef int32_t i32;
typedef size_t size;

#define EXIT_APP abort();

#define EXIT_APP abort()
#define REPORT_ASSERT_FAILURE(expr, file, line, message) \
std::cout << "ASSERTION FAILURE: " << #expr << " in file: " << file << " on line: " << line \
<< std::endl; \
std::cout << " Message: " << message << std::endl;

// Custom assert macro
#define CC_ASSERT(expr, message) \
if (expr) \
{} \
else \
{ \
REPORT_ASSERT_FAILURE(#expr, __FILE__, __LINE__, message); \
EXIT_APP \
}
std::cout << "ASSERTION FAILURE: " << #expr << " in file: " << file << " on line: " << line \
<< "\n Message: " << message << std::endl

#define CC_ASSERT(expr, msg) \
expr || (REPORT_ASSERT_FAILURE(expr, __FILE__, __LINE__, msg) && [](){EXIT_APP; return true;}())

#define OUT

Expand Down
2 changes: 1 addition & 1 deletion engine/render/renderer/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Renderer

int GetCurrentFrameIndex() const
{
CC_ASSERT(!isFrameStarted, "Can't get frame index when frame is not in progress!")
CC_ASSERT(!isFrameStarted, "Can't get frame index when frame is not in progress!");
return currentFrameIndex;
}

Expand Down
2 changes: 1 addition & 1 deletion engine/render/renderer/framebuffer/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Framebuffer::Initialise(const Framebuffer::Config& config, const VkDevice&

CC_ASSERT(vkCreateFramebuffer(device, &frameBufferInfo, nullptr, OUT & framebuffers[i]) ==
VK_SUCCESS,
"Failed to create framebuffer")
"Failed to create framebuffer");
}
}

Expand Down
4 changes: 3 additions & 1 deletion engine/render/renderer/material/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ Material::Property& Material::GetProperty(Utils::StringId id)
if (id == property.id) return property;
}

CC_ASSERT(false, "No property with ID: " << id << " exists!");
CC_ASSERT(false,
(std::string("No property with ID: ") + std::to_string(id) + std::string(" exists!"))
.c_str());
}

void Material::BuildMaterial()
Expand Down
3 changes: 2 additions & 1 deletion engine/render/renderer/model/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ void Model::LoadModelFromFile(const char* filePath)
std::vector<tinyobj::material_t> materials;
std::string warn, err;

CC_ASSERT(tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, filePath), warn + err);
CC_ASSERT(tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, filePath),
(warn + err).c_str());

std::vector<Vertex> objVertices;
std::vector<u32> objIndices;
Expand Down
2 changes: 1 addition & 1 deletion engine/render/renderer/pass/RenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void RenderPass::Initialise(const RenderPass::Config& config)

CC_ASSERT(
vkCreateRenderPass(device, &renderPassCreateInfo, nullptr, OUT & renderPass) == VK_SUCCESS,
"Failed to create render pass!")
"Failed to create render pass!");
}

void RenderPass::Initialise(RenderPass& renderpass, const RenderPass::Config& config)
Expand Down
4 changes: 2 additions & 2 deletions engine/render/renderer/pipeline/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Utils::Array<char> Pipeline::ReadFile(const char* filePath)
// Read the file as binary and consume the entire file.
std::ifstream file {filePath, std::ios::ate | std::ios::binary};

CC_ASSERT(file.is_open(), std::string("Could not find file: ") + filePath);
CC_ASSERT(file.is_open(), (std::string("Could not find file: ") + filePath).c_str());

// Since we consumed the entire file, we can tell the size by checking where
// the file stream is reading from (which presumably is at the end of the file).
Expand Down Expand Up @@ -138,7 +138,7 @@ void Pipeline::CreateGraphicsPipeline(const PipelineConfig::ShaderConfig* shader
&pipelineCreateInfo,
nullptr,
OUT & graphicsPipeline) == VK_SUCCESS,
"Failed to create graphics pipeline!")
"Failed to create graphics pipeline!");
}

void Pipeline::RecreatePipeline(const PipelineConfig::ShaderConfig* shaders,
Expand Down
4 changes: 2 additions & 2 deletions engine/render/renderer/swapchain/Swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void SwapChain::CreateSwapChain()

CC_ASSERT(
vkCreateSwapchainKHR(device.Device(), &createInfo, nullptr, OUT & swapChain) == VK_SUCCESS,
"Failed to create Swapchain!")
"Failed to create Swapchain!");

swapchainImages = FrameImages(&device, surfaceFormat.format);

Expand Down Expand Up @@ -277,7 +277,7 @@ void SwapChain::CreateSyncObjects()
OUT & renderFinishedSemaphores[i]) == VK_SUCCESS &&
vkCreateFence(device.Device(), &fenceInfo, nullptr, OUT & inFlightFences[i]) ==
VK_SUCCESS,
"Failed to create synchronization objects fora frame!")
"Failed to create synchronization objects fora frame!");
}
}

Expand Down

0 comments on commit 4c7217d

Please sign in to comment.