# Int32 wrap in shared\_memory\_communicator.py of LearningAgents

**URL:** <https://forums.unrealengine.com/t/int32-wrap-in-shared-memory-communicator-py-of-learningagents/2742446>\
**Category:** AI\
**Tags:** Python, unreal-engine, Learning-Agents, bug-report\
**Created:** [August 10, 2026, 8:18am UTC](https://forums.unrealengine.com/t/int32-wrap-in-shared-memory-communicator-py-of-learningagents/2742446 "2026-08-10T08:18:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_YAF\_Lightbringer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_YAF\_Lightbringer](https://forums.unrealengine.com/u/_YAF_Lightbringer)\
**Post date:** [August 10, 2026, 8:18am UTC](https://forums.unrealengine.com/t/int32-wrap-in-shared-memory-communicator-py-of-learningagents/2742446/1 "2026-08-10T08:18:21Z")

</div>

Hi there,

there’s some rather unfortunate error handling in the shared memory communicator of Learning Agents on the python side that silently shreds larger datasets:

Line 45:

```python
size = int(np.prod(shape) * np.dtype(dtype).itemsize)

```

will easily wrap around into the negatives if the dataset is reasonably large, since np.prods will produce an int32 by default. For example: if my dataset for behavior cloning is 110.458 steps with an observation dimension of 5.517 (multiplied by sizeof(float32) = 4), the requested size is 2.437.587.144 but then becomes −1.857.380.152. The real problem is though, that the communicator just silently produces an all zero array instead of failing. The validity of the returned handle is never checked again.

Turning this into an int64 mitigates the problem, because too large arrays will most likely lead to an out-of-memory error and force a hard crash, but the else path should probably lead the system into an error state.

Something like:

```python
def shared_memory_map_array(guid, shape, dtype, create=False):
  element_num = int(np.prod(shape, dtype=np.int64)) #main change
  size = element_num * int(np.dtype(dtype).itemsize)
  
  if size > 0:
    was_error = False
 
    try:
        handle = SharedMemory(guid, create, size)
    except FileExistsError:
        if create:
            # Windows has trouble cleaning up so use the existing shared memory - C++ side will reinitialize it
            handle = SharedMemory(guid, False, size)
            was_error = True

    assert handle is not None
    array = np.frombuffer(handle.buf, dtype=dtype, count=element_num).reshape(shape)
    if was_error:
        # if we were trying to create, but ended up mapping, then we are responsible for cleaning the memory and not C++
        array[:] = 0 

    if create:
        logger.info('Created shared memory with name: ' + guid)
    else:
        logger.info('Mapped existing shared memory with name: ' + guid)

    return handle, array
else:
    return None, np.empty(shape, dtype=dtype)

```

Edit: The forum editor mangled the indentations quite a bit. Copy & paste with care 😉

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [August 10, 2026, 1:53pm UTC](https://forums.unrealengine.com/t/int32-wrap-in-shared-memory-communicator-py-of-learningagents/2742446/2 "2026-08-10T13:53:06Z")

</div>

Thanks for reporting. I will give this a look

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [September 16, 2026, 3:20pm UTC](https://forums.unrealengine.com/t/int32-wrap-in-shared-memory-communicator-py-of-learningagents/2742446/3 "2026-09-16T15:20:49Z")

</div>

This fix was deployed to Main earlier this week.

Thanks!
