Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / image from memblock won't display as sprite

Author
Message
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Nov 2023 15:39
Building on my network/socket example, I'm trying to demonstrate sending data objects larger than the packet size limit of 1.4kb. As far as I can tell, that part works. I'm sending an image by create a memblock and sending the bytes over to the client (same as the server in this case) and creating a new memblock to write the data. Then I create an image from the memblock and finally create a sprite. The image dimensions seem to carry over just fine, but for some reason the color data is all zeros. The bytes are sent the exact same way, so I'm not sure why the first 12 bytes are perfectly fine but the rest are not. I'm not sure if its because sockets send signed bytes when everything else in agk using unsigned or what.


Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Nov 2023 16:00
Alright, so I changed the code to send integers instead of bytes. I know reading the bytes from a memblock image will put the components in opposite order as if reading just the integer (due to endian), but as long as I read and write those bytes the same way, that shouldn't matter. So I think the problem is with sockets sending SIGNED bytes, for whatever stupid reason.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Aidan
User Banned
Posted: 20th Nov 2023 17:49 Edited at: 20th Nov 2023 18:28
You have mpointer in your for loop but increasing it at the same time in the for loop.

This will have undesired affects

Maybe change line 72 on the getmemblockbyte from mpointer to " i " instead



To



Programming 1 o 1

We shouldn't increase a value that is embedded in a for loop
and increase inside a for loop cause it will just skip values left right and centre and produce undesired results.

Maybe you just probably missed that.

To test the send byte - maybe test that command by sending a few single bytes manually to prove if that command works or not.
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Nov 2023 18:52
ahh, crap. rookie mistake! The more I look at that loop now the more I see wrong with it.

It's strange that when I changed it to use an integer and step 4 it worked.


Regardless, I need to rewrite this loop without being a complete idiot.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Aidan
User Banned
Posted: 20th Nov 2023 18:55 Edited at: 20th Nov 2023 19:05
There is the steps of 4 to a PNG too. Happy you got your integers 4 to bytes 1 correct.

I'm dumbfoundered though that it still worked

I've got to change my teachers lol

But I'm all for redundancy coding
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Nov 2023 19:05 Edited at: 20th Nov 2023 19:07
Hmm in theory this should be working. I do get an image but it's skewed, so something isn't lining up correctly. This was suppose to be a simple 10min project.......

Nevermind, another stupid typo. This works fine now. And I'm going to lunch before more brain cells die today.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Aidan
User Banned
Posted: 20th Nov 2023 19:07 Edited at: 20th Nov 2023 19:10
Don't forget your 12 bytes at beginning... Add 12

Edit

Forget me too, you need to send the full menblock Inc width and height. I forget your sending data over to a client

I'm happy you sussed it
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Nov 2023 19:09
The 12 byte header doesn't matter, I'm sending all the bytes from the memblock in order and they'll be written on the receiving end in the same order. The loop remains agnostic about what's being sent, only the receiving end really needs to know it's an image so it knows how to convert the memblock back.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Aidan
User Banned
Posted: 20th Nov 2023 19:15
Thank you for your help phaelax, it will help lots of others on how to do it

Login to post a reply

Server time is: 2023-12-11 15:00:34
Your offset time is: 2023-12-11 15:00:34