Skip to content

Commit

Permalink
Fix a bug that would cause SHADERed to crash on creating cubemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
dfranx committed Apr 25, 2021
1 parent fbc077f commit d41743a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[v1.5.2]
+ fix a critical bug that would cause SHADERed to not store proper texture paths in project files
+ fix a bug that would cause SHADERed to crash on creating cubemaps
+ fix a bug that caused the geometry shader file dialog to be unresponsive
+ fix a bug that would crash SHADERed when a project file is referencing an texture that doesn't exist

Expand Down
2 changes: 1 addition & 1 deletion src/SHADERed/Objects/ObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace ed {
int nrChannels = 0;

if (!isDDS) {
stbi_load(path.c_str(), &w, &h, &nrChannels, 0);
data = stbi_load(path.c_str(), &w, &h, &nrChannels, 0);
} else {
ddsImage = dds_load_from_file(path.c_str());

Expand Down
29 changes: 16 additions & 13 deletions src/SHADERed/Objects/ProjectParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,8 @@ namespace ed {
bool isKeyboardTexture = (item->Type == ObjectType::KeyboardTexture);

std::string texOutPath = item->Name;
if ((isTexture && !isKeyboardTexture) || isAudio) {
if (std::filesystem::path(item->Name).is_absolute())
texOutPath = GetRelativePath(item->Name);
else
texOutPath = GetRelativePath(std::filesystem::absolute(std::filesystem::path(oldProjectPath) / item->Name).string());
}
if ((isTexture && !isKeyboardTexture) || isAudio)
texOutPath = GetTexturePath(item->Name, oldProjectPath);

std::string typeName = "texture";
if (isBuffer) typeName = "buffer";
Expand Down Expand Up @@ -635,12 +631,12 @@ namespace ed {

textureNode.append_attribute("cube").set_value(isCube);

textureNode.append_attribute("left").set_value(texmaps[0].c_str());
textureNode.append_attribute("top").set_value(texmaps[1].c_str());
textureNode.append_attribute("front").set_value(texmaps[2].c_str());
textureNode.append_attribute("bottom").set_value(texmaps[3].c_str());
textureNode.append_attribute("right").set_value(texmaps[4].c_str());
textureNode.append_attribute("back").set_value(texmaps[5].c_str());
textureNode.append_attribute("left").set_value(GetTexturePath(texmaps[0], oldProjectPath).c_str());
textureNode.append_attribute("top").set_value(GetTexturePath(texmaps[1], oldProjectPath).c_str());
textureNode.append_attribute("front").set_value(GetTexturePath(texmaps[2], oldProjectPath).c_str());
textureNode.append_attribute("bottom").set_value(GetTexturePath(texmaps[3], oldProjectPath).c_str());
textureNode.append_attribute("right").set_value(GetTexturePath(texmaps[4], oldProjectPath).c_str());
textureNode.append_attribute("back").set_value(GetTexturePath(texmaps[5], oldProjectPath).c_str());
}

if ((isTexture && !isKeyboardTexture) || isTexture3D) {
Expand All @@ -663,7 +659,7 @@ namespace ed {
ImageObject* iobj = item->Image;

if (iobj->DataPath[0] != 0)
textureNode.append_attribute("data").set_value(iobj->DataPath);
textureNode.append_attribute("data").set_value(GetTexturePath(iobj->DataPath, oldProjectPath).c_str());

textureNode.append_attribute("width").set_value(iobj->Size.x);
textureNode.append_attribute("height").set_value(iobj->Size.y);
Expand Down Expand Up @@ -1045,6 +1041,13 @@ namespace ed {
{
return std::filesystem::exists(GetProjectPath(str));
}
std::string ProjectParser::GetTexturePath(const std::string& texPath, const std::string& oldProjectPath)
{
if (std::filesystem::path(texPath).is_absolute())
return GetRelativePath(texPath);
else
return GetRelativePath(std::filesystem::absolute(std::filesystem::path(oldProjectPath) / texPath).string());
}
void ProjectParser::ResetProjectDirectory()
{
m_file = "";
Expand Down
1 change: 1 addition & 0 deletions src/SHADERed/Objects/ProjectParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace ed {
std::string GetRelativePath(const std::string& to);
std::string GetProjectPath(const std::string& projectFile);
bool FileExists(const std::string& file);
std::string GetTexturePath(const std::string& texPath, const std::string& oldProjectPath);

void ResetProjectDirectory();
inline void SetProjectDirectory(const std::string& path) { m_projectPath = path; }
Expand Down

0 comments on commit d41743a

Please sign in to comment.