PNG to iosImage crashes simulator

Hello.

I’m trying to transmit a picture from a desktop app to an iOS app. Sending is made thru a TCPSocket.

Here’s how I define the source (trimmed version):

[code]dim p as picture

p=ScreenshotMBS
DataToSend=PictureToPNGStringMBS§[/code]

Here’s how I try to re-construct the picture on iOS:

(ReceivedData is a MutableMemoryBlock)

[code]dim a as iOSImage

if LengthToReceive>0 then 'Receiving a picture
ReceivedData.Append me.AvailableData
if ReceivedData.Size>=LengthToReceive then 'All data picture received
a=iOSImage.FromData(ReceivedData)
Break
LengthToReceive=0
end if
Return
end if[/code]

When the “a=iOSImage.FromData(ReceivedData)” line is encountered, the simulator app just crashes, no error shown, no exception. I’m lost at how to debug that…
Any idea?

You will need to analyse the crash log located in this folder: ~/Library/Logs/DiagnosticReports/

Tried receivedData.Data instead?

Ok, I finally found the problem. The length was not identical between the data sent (bytes of data) and the received data (size of memoryblock).
Turns out “me.AvailableData” doesn’t clear the buffer while “me.ReadData(me.BytesAvailable)” does. Therefore, I was getting duplicate data. The ReadData method solves the issue and my picture is correctly rebuilt.

I find the language reference unclear for these 2 methods.
Thanks for your answer.

No. The problem lied in how I read the socket’s buffer (AvailableData instead of ReadData).
Thanks for your answer.

BTW: I read it too fast and marked it as “answering my question”, which is false. I’d like to unmark it, as it may mislead anyone having the same question. How should I do that?