mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 13:11:19 +01:00
fix(scripting): some crashed related to paths (#11378) c05b97d6d5
* fix(scripting): some crashed related to paths Co-authored-by: hernan <hernan@rive.app>
This commit is contained in:
@@ -1 +1 @@
|
||||
8e395d6bb04b096d0fcf308113c5458e7722e19c
|
||||
c05b97d6d53d78dbf95407cf2e2ae5334dd9cbf4
|
||||
|
||||
@@ -132,6 +132,8 @@ public:
|
||||
static uint64_t frameId() { return sm_frameId; }
|
||||
#ifdef TESTING
|
||||
static void incFrameId() { sm_frameId++; }
|
||||
#elif WITH_RIVE_TOOLS
|
||||
static void incFrameId() { sm_frameId++; }
|
||||
#endif
|
||||
void updateDataBinds(bool applyTargetToSource = true) override;
|
||||
void host(ArtboardHost* artboardHost);
|
||||
|
||||
@@ -252,11 +252,15 @@ public:
|
||||
static constexpr uint8_t luaTag = LUA_T_COUNT + 30;
|
||||
static constexpr const char* luaName = "PathData";
|
||||
static constexpr bool hasMetatable = true;
|
||||
RenderPath* renderPath(lua_State* L);
|
||||
|
||||
protected:
|
||||
rcp<RenderPath> m_renderPath;
|
||||
|
||||
bool m_isRenderPathDirty = true;
|
||||
|
||||
private:
|
||||
uint64_t m_renderFrameId = 0;
|
||||
};
|
||||
|
||||
class ScriptedPath : public ScriptedPathData
|
||||
@@ -264,13 +268,9 @@ class ScriptedPath : public ScriptedPathData
|
||||
public:
|
||||
ScriptedPath() {}
|
||||
ScriptedPath(const RawPath* path) : ScriptedPathData(path) {}
|
||||
RenderPath* renderPath(lua_State* L);
|
||||
static constexpr uint8_t luaTag = LUA_T_COUNT + 2;
|
||||
static constexpr const char* luaName = "Path";
|
||||
static constexpr bool hasMetatable = true;
|
||||
|
||||
private:
|
||||
uint64_t m_renderFrameId = 0;
|
||||
};
|
||||
|
||||
class ScriptedGradient
|
||||
@@ -423,7 +423,7 @@ public:
|
||||
void save(lua_State* L);
|
||||
void restore(lua_State* L);
|
||||
void transform(lua_State* L, const Mat2D& mat2d);
|
||||
void clipPath(lua_State* L, ScriptedPath* path);
|
||||
void clipPath(lua_State* L, ScriptedPathData* path);
|
||||
Renderer* validate(lua_State* L);
|
||||
|
||||
static constexpr uint8_t luaTag = LUA_T_COUNT + 9;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
using namespace rive;
|
||||
|
||||
RenderPath* ScriptedPath::renderPath(lua_State* L)
|
||||
RenderPath* ScriptedPathData::renderPath(lua_State* L)
|
||||
{
|
||||
if (m_isRenderPathDirty)
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ void ScriptedRenderer::transform(lua_State* L, const Mat2D& mat2d)
|
||||
m_renderer->transform(mat2d);
|
||||
}
|
||||
|
||||
void ScriptedRenderer::clipPath(lua_State* L, ScriptedPath* path)
|
||||
void ScriptedRenderer::clipPath(lua_State* L, ScriptedPathData* path)
|
||||
{
|
||||
validate(L);
|
||||
m_renderer->clipPath(path->renderPath(L));
|
||||
|
||||
@@ -213,6 +213,21 @@ void ScriptedObject::scriptUpdate()
|
||||
bool ScriptedObject::scriptInit(LuaState* luaState)
|
||||
{
|
||||
auto state = luaState->state;
|
||||
|
||||
// Clean up old references if reinitializing
|
||||
if (m_state != nullptr && (m_self != 0 || m_context != 0))
|
||||
{
|
||||
if (m_self != 0)
|
||||
{
|
||||
lua_unref(m_state->state, m_self);
|
||||
m_self = 0;
|
||||
}
|
||||
if (m_context != 0)
|
||||
{
|
||||
lua_unref(m_state->state, m_context);
|
||||
m_context = 0;
|
||||
}
|
||||
}
|
||||
for (auto prop : m_customProperties)
|
||||
{
|
||||
auto scriptInput = ScriptInput::from(prop);
|
||||
|
||||
@@ -59,7 +59,8 @@ void ScriptedPathEffect::updateEffect(PathProvider* pathProvider,
|
||||
}
|
||||
else
|
||||
{
|
||||
auto scriptedPath = (ScriptedPath*)lua_touserdata(state, -1);
|
||||
auto scriptedPath =
|
||||
(ScriptedPathData*)lua_touserdata(state, -1);
|
||||
auto rawPath = path->mutableRawPath();
|
||||
rawPath->addPath(scriptedPath->rawPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user