StreamingSocket bad access


#1

Hi!

I’m having some issues setting up a tcp socket using the StreamingSocket class.

I have a gui Component class, which has a pointer to another class handling Network IO.

I have a Slider callback in the gui class, which calls:

netIOManagerp->SendOnStreamSock(cc_buf, 3);

Nothing complicated. My SendOnStreamSock function is as follows:

int NetIOManager::SendOnStreamSock(uint8_t buf[], uint8_t buf_len)
{

    int nw = 0;

    if(streamSock.isConnected())
    {
        nw = streamSock.write(buf, buf_len);
    
        if(nw == -1)
        {
            std::cout << "ERROR writing  to streamSock..." << std::endl;
        }    
        else
        {
            std::cout << "Wrote: " << nw << " bytes to TCP sock!" << std::endl;
        }
    }
    
    return nw;
}

However, the connected variable of streamSock returns a BAD_ACCESS when isConnected() is called.

Worth noting that streamSock is bound and connected in NetIOManager's constructor, and calling isConnected() here returns true.

I must be missing something really simple…any help would be greatly appreciated!

Many thanks!


#2

If such a basic member variable access crashes, then your streamSock object is probably a dangling pointer…


#3

I’m not sure how that can be the case, there isn’t anywhere where the program would have a chance to delete the object, as the badd access is thrown almost immediately after the app launches.

I have tried making streamSock a ScopedPointer, but then I get the following line in the ScopedPointer class returning a bad_access:

/** Lets you access methods and properties of the object that this ScopedPointer refers to. */ inline ObjectType* operator->() const noexcept

I really don’t understand where the socket can be being deleted.

Also thanks for your prompt response.