Fix crash on effects parsing

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2023-02-09 00:22:48 +01:00
parent 3d8452ee9a
commit 64d9c2e4e6
11 changed files with 59 additions and 67 deletions

View File

@ -128,7 +128,7 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer& containe
{
auto effectVisible = jsonFindUserConfig <CUserSettingBoolean> (data, "visible", true);
if (!effectVisible->processValue (scene->getProject ()->getProperties ()))
if (!effectVisible->processValue (scene->getProject ().getProperties ()))
continue;
object->insertEffect (
@ -146,12 +146,12 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer& containe
glm::vec3 CObject::getOrigin () const
{
return this->m_origin->processValue (this->getScene ()->getProject ()->getProperties ());
return this->m_origin->processValue (this->getScene ()->getProject ().getProperties ());
}
glm::vec3 CObject::getScale () const
{
return this->m_scale->processValue (this->getScene ()->getProject ()->getProperties ());
return this->m_scale->processValue (this->getScene ()->getProject ().getProperties ());
}
const glm::vec3& CObject::getAngles () const
@ -177,7 +177,7 @@ const std::vector<uint32_t>& CObject::getDependencies () const
bool CObject::isVisible () const
{
// TODO: cache this
return this->m_visible->processValue (this->getScene ()->getProject ()->getProperties ());
return this->m_visible->processValue (this->getScene ()->getProject ().getProperties ());
}
CScene* CObject::getScene () const

View File

@ -9,13 +9,11 @@
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Assets;
CProject::CProject (std::string title, std::string type, CWallpaper* wallpaper, CContainer& container) :
CProject::CProject (std::string title, std::string type, CContainer& container) :
m_title (std::move (title)),
m_type (std::move (type)),
m_wallpaper (wallpaper),
m_container (container)
{
this->m_wallpaper->setProject (this);
}
CProject* CProject::fromFile (const std::string& filename, CContainer& container)
@ -30,25 +28,18 @@ CProject* CProject::fromFile (const std::string& filename, CContainer& container
std::transform (type.begin (), type.end (), type.begin (), tolower);
CProject* project = new CProject (title, type, container);
if (type == "scene")
{
wallpaper = CScene::fromFile (file, container);
}
wallpaper = CScene::fromFile (file, *project, container);
else if (type == "video")
{
wallpaper = new CVideo (file.c_str ());
}
wallpaper = new CVideo (file.c_str (), *project);
else if (type == "web")
sLog.exception ("Web wallpapers are not supported yet");
else
sLog.exception ("Unsupported wallpaper type: ", type);
CProject* project = new CProject (
title,
type,
wallpaper,
container
);
project->setWallpaper (wallpaper);
if (general != content.end ())
{
@ -69,6 +60,11 @@ CProject* CProject::fromFile (const std::string& filename, CContainer& container
return project;
}
void CProject::setWallpaper (CWallpaper* wallpaper)
{
this->m_wallpaper = wallpaper;
}
CWallpaper* CProject::getWallpaper () const
{
return this->m_wallpaper;

View File

@ -27,8 +27,9 @@ namespace WallpaperEngine::Core
CContainer& getContainer ();
protected:
CProject (std::string title, std::string type, CWallpaper* wallpaper, CContainer& container);
CProject (std::string title, std::string type, CContainer& container);
void setWallpaper (CWallpaper* wallpaper);
void insertProperty (Projects::CProperty* property);
private:
std::vector<Projects::CProperty*> m_properties;

View File

@ -9,6 +9,7 @@
using namespace WallpaperEngine::Core;
CScene::CScene (
CProject& project,
CContainer& container,
Scenes::CCamera* camera,
glm::vec3 ambientColor,
@ -28,7 +29,7 @@ CScene::CScene (
CUserSettingVector3* clearColor,
Scenes::CProjection* orthogonalProjection,
glm::vec3 skylightColor) :
CWallpaper (Type),
CWallpaper (Type, project),
m_container (container),
m_camera (camera),
m_ambientColor (ambientColor),
@ -51,7 +52,7 @@ CScene::CScene (
{
}
CScene* CScene::fromFile (const std::string& filename, CContainer& container)
CScene* CScene::fromFile (const std::string& filename, CProject& project, CContainer& container)
{
std::string stringContent = WallpaperEngine::FileSystem::loadFullFile (filename, container);
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container));
@ -80,6 +81,7 @@ CScene* CScene::fromFile (const std::string& filename, CContainer& container)
auto skylightcolor = jsonFindDefault <std::string> (*general_it, "skylightcolor", "0 0 0");
CScene* scene = new CScene (
project,
container,
Scenes::CCamera::fromJSON (*camera_it),
WallpaperEngine::Core::aToColorf(ambientcolor),
@ -143,17 +145,17 @@ const glm::vec3 &CScene::getAmbientColor() const
const bool CScene::isBloom () const
{
return this->m_bloom->processValue (this->getProject ()->getProperties ());
return this->m_bloom->processValue (this->getProject ().getProperties ());
}
double CScene::getBloomStrength () const
{
return this->m_bloomStrength->processValue (this->getProject ()->getProperties ());
return this->m_bloomStrength->processValue (this->getProject ().getProperties ());
}
double CScene::getBloomThreshold () const
{
return this->m_bloomThreshold->processValue (this->getProject ()->getProperties ());
return this->m_bloomThreshold->processValue (this->getProject ().getProperties ());
}
const bool CScene::isCameraFade () const
@ -208,7 +210,7 @@ const double CScene::getCameraShakeSpeed () const
glm::vec3 CScene::getClearColor () const
{
return this->m_clearColor->processValue (this->getProject ()->getProperties ());
return this->m_clearColor->processValue (this->getProject ().getProperties ());
}
Scenes::CProjection* CScene::getOrthogonalProjection () const

View File

@ -17,7 +17,7 @@ namespace WallpaperEngine::Core
class CScene : public CWallpaper
{
public:
static CScene* fromFile (const std::string& filename, CContainer& container);
static CScene* fromFile (const std::string& filename, CProject& project, CContainer& container);
const std::map<uint32_t, CObject*>& getObjects () const;
const std::vector<CObject*>& getObjectsByRenderOrder () const;
@ -45,6 +45,7 @@ namespace WallpaperEngine::Core
friend class CWallpaper;
CScene (
CProject& project,
CContainer& container,
Scenes::CCamera* camera,
glm::vec3 ambientColor,

View File

@ -4,9 +4,8 @@
using namespace WallpaperEngine::Core;
CVideo::CVideo (
std::string filename) :
CWallpaper (Type),
CVideo::CVideo (std::string filename, CProject& project) :
CWallpaper (Type, project),
m_filename (std::move(filename))
{
}

View File

@ -16,7 +16,7 @@ namespace WallpaperEngine::Core
class CVideo : public CWallpaper
{
public:
explicit CVideo (std::string filename);
explicit CVideo (std::string filename, CProject& project);
const std::string& getFilename ();

View File

@ -4,18 +4,13 @@
using namespace WallpaperEngine::Core;
CWallpaper::CWallpaper (std::string type) :
CWallpaper::CWallpaper (std::string type, CProject& project) :
m_type (std::move(type)),
m_project (nullptr)
m_project (project)
{
}
CProject* CWallpaper::getProject () const
CProject& CWallpaper::getProject () const
{
return this->m_project;
}
void CWallpaper::setProject (CProject* project)
{
this->m_project = project;
}

View File

@ -16,17 +16,15 @@ namespace WallpaperEngine::Core
template<class T> bool is () { return this->m_type == T::Type; }
CWallpaper (std::string type);
CWallpaper (std::string type, CProject& project);
CProject* getProject () const;
CProject& getProject () const;
protected:
friend class CProject;
void setProject (CProject* project);
private:
CProject* m_project;
CProject& m_project;
std::string m_type;
};

View File

@ -247,7 +247,7 @@ const std::vector<Effects::CFBO*>& CEffect::getFbos () const
bool CEffect::isVisible () const
{
return this->m_visible->processValue (this->m_object->getScene ()->getProject ()->getProperties ());
return this->m_visible->processValue (this->m_object->getScene ()->getProject ().getProperties ());
}
Effects::CFBO* CEffect::findFBO (const std::string& name)

View File

@ -101,12 +101,12 @@ const std::string& CImage::getAlignment () const
float CImage::getAlpha () const
{
return this->m_alpha->processValue (this->getScene ()->getProject ()->getProperties ());
return this->m_alpha->processValue (this->getScene ()->getProject ().getProperties ());
}
glm::vec3 CImage::getColor () const
{
return this->m_color->processValue (this->getScene ()->getProject ()->getProperties ());
return this->m_color->processValue (this->getScene ()->getProject ().getProperties ());
}
float CImage::getBrightness () const