...just before crashing (I say unexpected because I've not made use of anything similar to "LayerByDepth" function in my scripts at all, so I guess it's an internal error that for some reason is leaking into the lua console window? I don't really know, but informing about it just in case is useful.
The part of the embedded script I'm trying to develop is a little more complex, it consists on not allowing you to drag a layer (normally the layer containing the script) out of the context it has been designed to act, but I have reduced it to the minimum to reproduce the crash as follows:
Code: Select all
function LayerScript(moho)
doc = moho.document
fixedLayer = moho.layer
if oldLayerPos ~= nil then
if oldLayerPos ~= doc:LayerAbsoluteID(fixedLayer) then
print("Old Placement: " .. oldLayerPos)
print("New Placement: " .. doc:LayerAbsoluteID(fixedLayer))
moho:PlaceLayerBehindAnother(fixedLayer, doc:LayerByAbsoluteID(oldLayerPos))
print("Final Placement: " .. oldLayerPos)
print("------------------")
end
end
oldLayerPos = doc:LayerAbsoluteID(fixedLayer)
end
It simply moves the layer you drag in palette to its original position (well, it fails if you drag it down at the same level, but that would require some more code beside the point), and here is the same script with a quick-testing project:
rl_fixed_layer_20220731-2258.zip
Where as soon as you drag the red layer into the group, the program crashes... Well, I've tried a lot of things, even the "PlaceLayerInGroup" one with similar results. I've also tried to ensure the correct layer IDs are provided at any time, but it doesn't seem to be the cause of the crashes as far as I can tell. The problem, as I said, seems to be more related to this functions somehow messing the way Moho deals with layers depth/ordering system and the fact a script try to move a layer into/out of a group at the same time it's being dragged by user in palette.
Well, I've tried to keep it simple, sorry if it still sounded messy after all... but maybe some of you can see something around a possible way to avoid the crashes or an explanation of why they happen I'm simply not able to. Thanks for reading in any case!