to retrieve images from the vision sensors. After running for a period of time, Coppelia crashes. My scene contains 10 vision sensors, and I retrieve images from each one in every iteration of the loop.
This is the exception reported by Visual Studio during the crash: Unhandled exception at 0x00007FFFEB977885 (ntdll.dll) in coppeliaSim.exe: 0xC0000374: The heap is corrupted. (Parameter: 0x00007FFFEBA2D0E0).
int ret = simHandleVisionSensor(sim_handle_all, nullptr, nullptr);
There should be no memory to release.
Cheers
In Debug mode, it runs very stably. When I tried testing in Release mode, Coppelia started crashing again. This is the exception reported by Visual Studio: An unhandled exception occurred at 0x00007FFFEB977885 (ntdll.dll) (in coppeliaSim.exe): 0xC0000374: The heap is corrupted. (Parameter: 0x00007FFFEBA2D0E0).
coppelia wrote: 05 Nov 2025, 08:24
Can you reproduce the problem when using a script instead of a plugin? (i.e. calling sim.handleVisionSensor instead of simHandleVisionSensor)
sim.handleVisionSensor is basically implemented in a same way and should produce the same error. Here the sim.handleVisionSensor implementation:
int _simHandleVisionSensor(luaWrap_lua_State* L)
{
TRACE_LUA_API;
LUA_START("sim.handleVisionSensor");
int retVal = -1; // means error
if (checkInputArguments(L, &errorString, lua_arg_integer, 0))
{
double* auxVals = nullptr;
int* auxValsCount = nullptr;
retVal = CALL_C_API(simHandleVisionSensor, luaToInt(L, 1), &auxVals, &auxValsCount);
if (retVal != -1)
{
luaWrap_lua_pushinteger(L, retVal);
int tableCount = 0;
if (auxValsCount != nullptr)
{
tableCount = auxValsCount[0];
int off = 0;
for (int i = 0; i < tableCount; i++)
{
pushDoubleTableOntoStack(L, auxValsCount[i + 1], auxVals + off);
off += auxValsCount[i + 1];
}
delete[] auxValsCount;
delete[] auxVals;
}
for (int i = tableCount; i < 2; i++)
{
pushIntTableOntoStack(L, 0, nullptr); // return at least 2 aux packets, even empty
tableCount++;
}
LUA_END(1 + tableCount);
}
}
LUA_RAISE_ERROR_OR_YIELD_IF_NEEDED(); // we might never return from this!
luaWrap_lua_pushinteger(L, retVal);
LUA_END(1);
}
Cheers
I attempted to test using a script, but I found that sim.handleVisionSensor always returns a detectionCount of 0. This occurs regardless of whether I pass in sim.handle_all or a specific vision sensor handle as the parameter. Is this normal?
The first returned value should be exactly the same as for the C version of the same API function. If your vision sensors do not trigger a detection, then this is normal. By default, a vision sensor does not trigger a detection. To trigger a detection, attach a simulation script to the vision sensor with this code in it: