I've manged to build the demo from the source code without issues, however when trying to link the compiled lib into another project I get issues with the RadialLight class.
I define the RadialLight in the header of a game state class (using my own framework built on top of SFML) like so:
#pragma once
#include <VFrame/VState.h>
#include <Candle/Candle.hpp>
class PlayState : public VState
{
public:
typedef VState VSUPERCLASS;
PlayState() = default;
virtual void Initialise() override;
virtual void Update(float dt) override;
virtual void Draw(sf::RenderTarget& RenderTarget) override;
candle::RadialLight light;
candle::EdgeVector edges;
};
Also, implement a test example in the cpp like so:
#include "PlayState.h"
#include <VFrame/VGlobal.h>
#include "PauseScreen.h"
#include <Candle/Candle.hpp>
void PlayState::Initialise()
{
VSUPERCLASS::Initialise();
light.setRange(150);
edges.emplace_back(
sf::Vector2f(200.f, 100.f),
sf::Vector2f(200.f, 300.f));
}
void PlayState::Update(float dt)
{
VSUPERCLASS::Update(dt);
light.setPosition(VGlobal::p()->GetMousePosition());
light.castLight(edges.begin(), edges.end());
if (VGlobal::p()->Input->IsButtonPressed("Pause"))
{
OpenSubState(new PauseScreen());
}
}
void PlayState::Draw(sf::RenderTarget& RenderTarget)
{
VSUPERCLASS::Draw(RenderTarget);
RenderTarget.draw(light);
}
It compiles in Visual Studio 2017, but when I try to run I get a crash from an Access Violation within MutexImpl::lock(). Going down the call stack, the source is the RadialLight class when calling the default constructor on the two sf::Texture objects within RadialLight.cpp:
namespace candle{
const float BASE_RADIUS = 400.0f;
bool l_texturesReady(false);
sf::Texture l_lightTextureFade;
sf::Texture l_lightTexturePlain;
void initializeTextures(){
I've found one way to resolve the crash, however. You can change these two to pointers (or better, smart unique pointers) and initialise the pointers in the initializeTextures function, that way the textures don't try to initialise before the main function is called.
std::unique_ptr<sf::Texture> l_lightTextureFade;
std::unique_ptr<sf::Texture> l_lightTexturePlain;
If you want to avoid smart pointers for compatibility, you could use raw pointers but then you would need to add a way to delete the pointer when the user wants to close the application.