Custom CPlusPlus POP freezing when switching windows

Hi TD community, first post here on forums so please let me know if the question/provided info can be improved. Thanks in advance for all the help.

I am developing a custom POP, but starting over from the base CudaPOP example because many things keep freezing with unknown causes. I read the API documentation from header files, forum posts, examples, CPlusPlus plugin dev guide from docs, and right now have a minimal project with console prints (environment variable TOUCH_TEXT_CONSOLE set to 1) used to check the call stack and some node informations.

The actual issue: even with just a couple of prints, and a base TD file with only a POP Point Generator connected to a CPlusPlus POP that loads the dll, the software often freezes without any apparent reason. After a good time fuzz-checking which interactions cause the freezing, I started noticing that, if I had happened to change windows (e.g. from TD window to console window, selecting some text, and focusing back to TD), the freeze would occur with the next interaction, be it re-initializing the class, force cooking the point generator, disconnecting the input, etc.

EDIT: I checked and it appears to freeze only if I try to select some text from the console window, not by just switching to it or to other windows/programs.

I am not really sure if this is a bug, or if I am interfering with other things happening under the hood that don’t like console prints or something like that. I can upload the base project and cpp files if needed, just in case here’s a snippet of what happens inside CudaPOP.cpp (which I have renamed into TestPOP.cpp):

#include "TestPOP.h"

#include <assert.h>
#include <cstdio>
#include <iostream>

// utils
#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
static inline void printStr(const char* msg) { std::cerr << msg << std::endl; }
static inline void printTitle(const char* msg) { std::cerr << "---" << msg << std::endl; }
#else
static inline void printStr(const char* msg) {}
static inline void printTitle(const char* msg) {}
#endif

// omitted the 3 functions for DLL export, constructor and destructor methods
// omitted getGeneralInfo (contains only test prints)
// omitted forward declaration of all CUDA kernels, from kernels.cu file
// omitted helper functions for attribute retrieval and copy (from example)

void
TestPOP::execute(POP_Output* output, const OP_Inputs* inputs, void* reserved)
{
	printTitle("exec execute()");

	myError = nullptr;
	myWarning = nullptr;
	myExecuteCount++;

	if (!inputs) {
		printStr("Missing reference to OP_Inputs");
		myError = "Missing reference to OP_Inputs";
		printTitle("end execute()");
		return;
	}

	if (inputs->getNumInputs() > 0)
	{
		const OP_POPInput* input = inputs->getInputPOP(0);

#ifdef ENABLE_DEBUG
		char* IND = "\t";
		std::cerr << IND << "input information: " << std::endl << IND <<
			"opPath: " << input->opPath << std::endl << IND <<
			"opId: " << input->opId << std::endl << IND <<
			"totalCooks: " << input->totalCooks << std::endl;
#endif

		if (!input) {
			printStr("Missing reference to first input");
			myError = "Missing reference to first input";
			printTitle("end execute()");
			return;
		}

		printStr("Issue download operations");
		// omitted all download ops (same as example)
		uint32_t numPoints = 0;

		printStr("beginCUDAOperations()");
		myContext->beginCUDAOperations(nullptr);
		printStr("Inside CUDAOperations fence");
		myContext->endCUDAOperations(nullptr);
		printStr("endCUDAOperations()");

		printStr("assign all outputs");
		// omitted all set attribute ops (same as example)
	}
	printTitle("end execute()");
}

// omitted all the other standard methods

HW info: Windows 11 PC with RTX 3090, TouchDesigner 2025.32280, CUDA Toolkit 13.1.1. Compiling and debugging directly with Visual Studio 2022, with the provided .sln file modified to accomodate my filenames, CUDA version and architecture.

Additional context: I’m a CS graduate with C++ literacy currently working on an R&D project involving Touch and custom operators. I’m more of a beginner inside TouchDesigner, so that’s also why I could be missing many points. I chose the custom POP way because I’m trying to incorporate CUDA functionality in the project I am working on, and the data structures seem way more appropriate than those that could be used within a custom TOP.

Hello @hoolywear

I think this is the expected behavior of the Windows console when Quick Edit Mode is enabled. When you click and drag in the console on Windows, the system assumes you want to select text to copy. To allow this without the text constantly scrolling due to new output, the Windows console temporarily blocks its output stream. TouchDesigner continues running, but any write to stdout or stderr will stall execution until the selection is cleared.

1 Like

Indeed, this is it. When I press ESC while in the console to clear the selection, TD becomes operational again, apparently with no issues. Thank you!!

1 Like