Skip to content

Crash when connecting to a socket on iOS in distribution builds #442

Open

Description

@MenacingDwarf

I’m trying to build my project using Unreal Engine 5.4 for iOS. I use SocketIO 2.8.0 to connect to the backend. When trying to connect to the socket, a crash occurs. This only happens on iOS, only in Distribution builds, and only on Unreal 5.4. There are no problems on Unreal 5.2. Callstack: crashlog.txt

The callstack may be slightly different, but the problem is always when allocating or deallocating memory. I suspect that this may be a race condition and is related to some peculiarities of working with memory on iOS.

I tried using other versions of plugin, other versions of xcode, tried to build socket io using both c++20 and c++17, nothing helps.

Activity

  1. getnamo commented on Dec 2, 2024

    @getnamo
    Owner

    likely related issues: #431 (5.3) and #402

    iOS is not a primary platform I develop on, will likely have to depend on other devs to identify issue. Once a pull request with fix is opened I can merge it.

  2. omaralmasoud commented on Mar 17, 2026

    @omaralmasoud
    Contributor

    I was experiencing consistent crashes on iOS only in TestFlight / Distribution builds, while everything worked perfectly in Development builds.

    The crash log showed:

    ___BUG_IN_CLIENT_OF_LIBMALLOC_POINTER_BEING_FREED_WAS_NOT_ALLOCATED

    and the stack trace pointed into websocketpp / socket.io-client-cpp during HTTP header parsing.

    Workaround That Fixed It

    For me, the issue appears to be related to memory allocation differences in iOS Shipping/Distribution builds.

    I resolved the crash by forcing Unreal Engine to use the ANSI allocator on iOS:

    using UnrealBuildTool;
    using System.Collections.Generic;

    public class YourProjectTarget : TargetRules
    {
        public YourProjectTarget(TargetInfo Target) : base(Target)
        {
            Type = TargetType.Game;
    
            if (Target.Platform == UnrealTargetPlatform.IOS)
            {
                GlobalDefinitions.Add("FORCE_ANSI_ALLOCATOR=1");
            }
        }
    }
    

    ### Steps

    Add the above to your Game Target (.Target.cs)

    Delete:

    • Binaries
    • Intermediate
    • Regenerate project files
    • Rebuild and archive again

    Notes

    • This issue seems specific to iOS distribution/TestFlight builds
    • Development builds may work fine, which can make this tricky to debug
    • Likely related to how Unreal’s allocator interacts with socket.io-client-cpp / websocketpp on iOS
  3. getnamo commented on Mar 18, 2026

    @getnamo
    Owner

    Nice spot, if you make a pull request with the suggested code changes I'll merge it.

  4. omaralmasoud commented on Mar 19, 2026

    @omaralmasoud
    Contributor

    Thanks! I've implemented the fix and opened a pull request with the changes.

    This resolved the iOS TestFlight/distribution crash on my side. Let me know if you'd like any adjustments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions