Avoiding invalidating saved scenes when implementing Read/Write



  • Hello there!

    I'm not quite sure if the issue I'm having is already explained elsewhere, although I did try to find guides and articles on this, but found nothing sufficient enough.

    So I implemented a SceneHook which writes data when a document is written and reads data when a document loads. That's fine and not the issue I'm having.

    The data that this SceneHook handles cannot be put into a container, but also has no effect on the contents of the scene. When a scene is now saved with that data internal to this SceneHook, it cannot be opened anymore without the plugin being installed, as Cinema reports an 'incorrect file structure' otherwise, basically corrupting every scene saved while this plugin is installed.

    I was under the impression that Cinema simply ignores data for nodes from a missing plugin, so I guess my implementation of the Write() function is just not quite right.

    Is there any documentation as to how reading and writing should be implemented, or is that actually expected behaviour?



  • @doppelgamer said in Avoiding invalidating saved scenes when implementing Read/Write:

    The data that this SceneHook handles cannot be put into a container,

    Why?

    I guess my implementation of the Write() function is just not quite right.

    I think it would make sense if you would show us your code here.

    Read()/Write() operates on a HyperFile. You find some examples in the HyperFile Manual and NodeData::Read() / NodeData::Write() Manual



  • @PluginStudent said in Avoiding invalidating saved scenes when implementing Read/Write:

    Why?

    Because the SceneHook makes use of plug-in internal classes. I guess it technically is possible to put this data into the node's container, however that would be far less efficient.

    I think it would make sense if you would show us your code here.

    I would if I was sure that it's unexpected behaviour by Cinema to not be able to read files anymore after a plug-in manually wrote into the file. The code is fairly standard abstraction of classes into primitive types, using the HyperFile's read/write interfaces.

    Read()/Write() operates on a HyperFile. You find some examples in the HyperFile Manual and NodeData::Read() / NodeData::Write() Manual

    Thank you for the links! Even though I read them carefully, I couldn't find anything I did any different, besides code within the Read() function checking for the 'value header', which mine doesn't.

    However, reading isn't the issue I'm having, or rather reading for my plug-in within my code. The problem is that scenes saved while this plug-in is installed cannot be opened anymore when the plug-in is not installed.

    Is this expected behaviour, and would putting this data into the node's BaseContainer solve this issue?



  • Hi,

    no, normally a missing plugin should not trip Cinema on loading a file where that plugin has had serialised some data into that file via NodeData::Write, as it would be just a dormant HyperFile block then.

    However, I am not quite sure about SceneHooks and if they are even supposed to be written into the document. It could very well be that the usual if I don't know it, I put a dummy node in-logic does not apply to a SceneHook. I always viewed a SceneHook as, well a hook, so something that should not be serialised, as it is unique to each context it runs in. For the same reason I would also doubt that the data container of a SceneHook is being serialised per document, but I might be wrong about this.

    Cheers,
    zipit



  • @zipit said in Avoiding invalidating saved scenes when implementing Read/Write:

    no, normally a missing plugin should not trip Cinema on loading a file where that plugin has had serialised some data into that file via NodeData::Write, as it would be just a dormant HyperFile block then.

    Yeah that's what I experienced with for example a BaseObject.

    However, I am not quite sure about SceneHooks and if they are even supposed to be written into the document. It could very well be that the usual if I don't know it, I put a dummy node in-logic does not apply to a SceneHook. I always viewed a SceneHook as, well a hook, so something that should not be serialised, as it is unique to each context it runs in. For the same reason I would also doubt that the data container of a SceneHook is being serialised per document, but I might be wrong about this.

    Now that I think about it, you may be right, a SceneHook seems a little unsuitable for what I'm trying to do. It is doing something on its own which it uses scene-specific data for, which is what I'm writing to and reading from the Hyperfile.

    Is there a more suitable way to store scene-specific data within a BaseDocument that is a little too complex to be put into its BaseContainer? I guess utilising GeData, although that could be a little overkill.



  • I still don't get what data would be too complex to write into a BaseContainer.

    You can store raw memory in a BaseContainer.

    If you only want to read/write to the document's BaseContainer, you could listen to the MSG_DOCUMENTINFO sent when the document is loaded and saved.



  • @PluginStudent said in Avoiding invalidating saved scenes when implementing Read/Write:

    I still don't get what data would be too complex to write into a BaseContainer.

    'Too complex' might be the wrong wording, it's more like the data is laid-out into classes with relations within each other. Again, storing this data within the NodeData's container is technically possible, but quite inefficient.

    You can store raw memory in a BaseContainer.
    If you only want to read/write to the document's BaseContainer, you could listen to the MSG_DOCUMENTINFO sent when the document is loaded and saved.

    I guess that's going to be a mixture I'm going to utilise. Thank you!

    Maybe someone from Maxon could look into this issue, I think it's quite important to communicate to plug-in developers that making a SceneHook write into a HyperFile will invalidate the scene file for future use without the respective plug-in.



  • hi,

    creating a scenhook or any kind of plugin will not make the hyperfile structure invalid. A SceneHookData inherit from NodeData.
    It does check if the plugin exist or not before calling the Read function.

    I couldn't reproduce the file structure error you are talking about.
    Maybe because my data structure is too simple (just a Int32)
    Can you try with a simplified data structure ? Share a simplified version of your code ? you can use sdk_support@maxon.net

    Cheers,
    Manuel


Log in to reply