Inconsistent Extension Re-initialization in TouchDesigner with Temporary Files and Indirect DAT Editing

Bug Report: Inconsistent Extension Re-initialization in TouchDesigner with Temporary Files and Indirect DAT Editing


Summary:
Extensions in TouchDesigner do not consistently reinitialize when edited through various indirect methods such as external editors using temporary files, or from editing one DAT’s contents via another. The changes to extension code do not properly take effect until the project is saved and reloaded, which creates significant challenges during development.


Steps to Reproduce:

  1. Create a new project in TouchDesigner (TD versions tested: 11880 and 11600, but seen as far back as 2022).
  2. Add a custom component with a Python extension.
  3. Edit the extension using any indirect method, such as:
  • Temporary files opened in an external editor (i.e., not synced files).
  • Modifying the content of one DAT from another DAT (via Python code or DAT references).
  • A custom component or tool that edits the content of a DAT indirectly (such as using websockets to update a DAT’s contents).
  1. When using an external editor, save the changes to the extension.
  2. Reinitialize the extension using the “Re-init” button on the component.
  3. Observe the behavior of the extension, particularly whether new functions or updates are applied.

Expected Behavior:
The extension should reinitialize fully after any modification, and all changes (including new or altered functions) should be reflected without the need for a project reload. Pressing “Re-init” should force the extension to fully refresh.


Observed Behavior:

  • The extension does not always reflect updates, even though the debug output indicates it has reinitialized.
  • Some old references to functions persist in memory, despite deleting or altering the extension code.
  • Even after deleting the code in the extension, some functions continue to work, while others do not update correctly.
  • The issue persists across different machines (Windows and macOS) and different projects.
  • This behaviour is inconsistent, but will occur in the outlined situations, even if not immediately

Potential Cause/Insights:

  • There seems to be an issue with caching and propagation, where older references to the extension’s functions or code are retained in memory.
  • This issue appears specifically when indirect editing methods are used, such as:
    • External editors using temporary files (not synced files).
    • Modifying the contents of a DAT indirectly from another DAT.
    • Custom components or external tools that update a DAT via methods such as websockets (in my case, my custom TDCode component).

Key Insights from the TouchDesigner Discord Discussion:

  1. @alphamoonbase.berlin:
    2.“I sometimes do have an issue where I would need to cut and paste a textDAT because it somehow was holding an older reference to the extension.”*
    3.“Mayve it is some moduleCaching and cooking propagation that is creating an issue.”*
  2. @noah | hard work party:
    5.“Are you editing the extension files externally? If so, are your extensions saved as external text files or are you using the temporary buffer that TouchDesigner creates?”*
  3. @shamanic (me):
    7.“I 100% have seen this issue before & not with my tool. I think the issue is deeper than just my tool’s indirect editing, but the fact that you seem to sync files over editor & never have issues vs I have always edited with temp files feels meaningful.”*
    8.“It may just be that devs that work with extensions and sync to an external editor are less likely to encounter these issues.”*
  4. @noah | hard work party:
    10.“I completely do not trust that buffer thing. Way too many failure modes. Never use it for anything more than a quick par exec or some kind of short callback thing.”*

Workarounds:

  • Synced files: Using synced external files avoids this issue and is the preferred method for external editing.
  • Direct DAT editing: Editing directly in the TouchDesigner DAT editor also avoids the issue.
  • Save and reload: Manually saving and reloading the project is a temporary workaround, but it disrupts workflow and slows development.

Additional Context:
This issue has been observed across different versions of TouchDesigner, multiple operating systems (Windows and macOS), and on multiple machines. It affects indirect editing workflows, especially those involving temporary files or external tools that indirectly modify DAT contents (such as via websockets or other non-DAT editor approaches).

It is particularly relevant for my custom tool, TDCode (not yet publicly released), which relies on websockets to update DAT contents. While I have no control over this bug, it’s critical that this functionality works reliably for my tool to be effective.


Request:
I recommend a deeper investigation into how TouchDesigner handles edits made through indirect methods (temporary files, inter-DAT updates, websockets, etc.). It would be helpful to explore how module caching and cook propagation affect the re-initialization of extensions.

Hi @shamanic

Thanks for the long report.

We will look into all this ASAP and get back to you.

We did do a recent change in internal builds that could be or not related and mitigate the issues you are encountering: Inconsistant Extension behavior when editing and saving - #3 by selina

Need to discuss further with developers.

Best,
Michel

Hi @JetXS ,

thanks for the fast respons

yes on first glance the issue highlighted in the linked post does seem related. hopefully any insights in my report can help get to the bottom of this

Cheers!

If anyone can find a way to reliably reproduce this it would help immensely. So far I haven’t been able to cause the problem even once. I have no doubt that it’s there, but something very specific is going on and it’s apparently quite difficult to find.

I will definitely keep trying on my end to establish reliable repro steps. at the moment repro is very inconsistent, with the main patterns seeming to be that : the ext is edited in an external editor via temp files, or else is edited through some other external means ( via python from another DAT for example ), storage of objects in the external, longer code of maybe 100-150 lines or more, appears to appear after more than one save & load of project containing ext.

I can share a toe I know has had the issue locally on my side in case it is helpful for diagnosing the issue. it contains FXMixer component which has an FXMixerExt, it also contains a version of my TDCode code editor for touchdesigner, which uses websockets to edit dats content.

here are the steps to repro the inconsistent behaviour in this project:

1: observe expected behaviour of FXMixer, change Num FX Layers to > 0 & change FX Layer dropdown to “feedbackEdge” , observe creation associated FXMixerLayer component & creation of parameters in associated FXMixerLayer component.

2: open TDCode & navigate to ext ( ctrl + t, then either alt + shift + s and search, or select dat from the dats menu dropdown on the base ) or enter FXMixer & edit FXMixerExt in external editor - open textport to view logs

3: delete all code inside of ext

4: auto re-init or manually re-init

5: in FXMixer , repeat step 1, observe creation of base component but failure of parameter creation. this should not be possible as all ext code has been deleted

fxmixer-viewer.15.toe (232.9 KB)

let me know if this helps. I have been able to repro this behaviour on two seperate machines, so it should display the same behaviour on your side

Hi,

The issue is that you keep a reference to the old extension in the Par Exec DAT, at the very top.

Use ext.FXMixerExt in your Par Exec DAT methods.

The module is only compiled once and you shouldn’t store the ext object outside of the methods to avoid keeping a reference to the old object in memory.

Best,
Michel

1 Like

ah I see, sorry for the misreport and thank you for the solution

No worries, report is appreciated and the problem is quite subtle.

1 Like