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 / loadImage bug is driving me nuts!

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Mar 2014 21:13 Edited at: 2nd Mar 2014 21:28
Already wasted an hour tracking the bug down to this code. I've tried loading different images using a hard-coded source name, images I know that can be loaded elsewhere in my program. I've basically eliminated everything down to img = loadImage("littleshrooms_0.png").

I comment that line out and everything is fine. What on earth is causing this line to cause a generic AppGameKit app crash? I simply cannot load an image within this code block and have no idea why.



I found a workaround. At first, I tried calling a function from here to load the image for me and return the ID, but that resulted in the same crash. But if I load the image from outside of this loop it'll work. Since I'm already keeping track of the image source, once I'm done reading my map file and exit out of the loading function THEN I can load the images. It makes no sense still as to why I can't load it here though.

The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 2nd Mar 2014 21:53
Just taking a quick look i have to ask why you are loading an image in a loop?

Seeing that you are hard coding the image filename, why not load this out of the loop into a temporary variable to hold the image ID, then in the loop just assign img to the temporary image ID? Saves a call to loadImage within a loop!

Just a thought?

www.bitmanip.com
All the juicy you could ever dream of!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Mar 2014 21:58
There's no reason why I shouldn't be able to load it in the loop. Here's a snippet of the XML I'm loading:



Once it detects imagelayer, it will loop through all the image tags until it finds the closing imagelayer. So as I detect the image source, why not load it then?

The image file was only hardcoded for testing, the source as you can see is being read from the xml. It's not loading the same image over and over as my initial example might have lead you to believe.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Mar 2014 23:03
I noticed the line;

and wondered about EOF checking, ie what happens if it reaches the end of the file before it finds the "/imagelayer" tag.

It looks like it just keeps retrying without end.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Mar 2014 00:20 Edited at: 3rd Mar 2014 00:20
That could cause an infinite loop if the XML wasn't complete, but even so it's not the cause of this issue. I've verified that all input is accurate, reading the file and parsing the data I want is ok and there are no infinite loop issues (using my example xml).

It's very strange. Here is the entire function in the snippet below. I can call img = loadImage("littleshrooms_0.png") pretty much any where inside that function except within the code block starting with if tag$ = "imagelayer".

Ok, now this same problem has crept up elsewhere. After I delete the loaded map ingame then load a new one, I get the same crash. And I've once again tracked it down to a loadImage command. Now this part isn't something I just added, this part has been working fine since I made this TMX library last year. I never had problems deleting and loading a new map before until now. I'm sure I could do a similar workaround as before.



David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 4th Mar 2014 11:58
Just an observation..



the command img = loadimage("littleshrooms_0.png") is used to 'ASSIGN' and ID to the loaded image.. As far as I know image ID's start at 1 and go up from there.. there can not be an image # 0 (zero)

by having the line above the loadimage say img = 0 you are forcing the code to try and make 0 = loadimage("littleshrooms_0.png") From what I see that will always error out.

While coding my games it was pointed out to me that it was beter to let AppGameKit assign the image ID's than for me to do something like this..



anyways, I think it's the line above the load image that is causing your problems.. img = 0

Just letting you know what I see,

Cheers!

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 4th Mar 2014 12:29
Quote: "by having the line above the loadimage say img = 0 you are forcing the code to try and make 0 = loadimage("littleshrooms_0.png")"

...or...
Perhaps simply clearing the variable before using it to receive the ID returned by loadimage.
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 4th Mar 2014 12:37
Yeah, I don't think zeroing out a variable before assigning it to the return value of a function is going to make any difference.

If it was:



Then we would have problem, big problem

01100001 01101110 01101111 01110100 01101000 01100101 01110010
01110000 01101111 01101001 01101110 01110100 01101100 01100101 01110011
01110011 01110011 01101001 01100111
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Mar 2014 18:56
It has nothing to do with setting the variable to 0 first, the variable is overwritten anyway when the function assigns the value.
It's like you're saying:
x = 0
x = 42

Is really:
x = 0
0 = 42


I only reset the variable anyway for testing purposes.

Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Mar 2014 00:57
If you're loading from xml files, remember to check for leading tabs, as well as spaces.
I ran into this issue with my own xml type parser. Notepad++ insiste on replacing 3 spaces with tab characters so I had to code my own trim leading spaces function to trim tabs too.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 6th Mar 2014 01:20
Add in an
if GetFileExists($imgFile) = 1
I have my own function that creates sprites basically it checks to see if the image file is already loaded from my array of image files/ids if not then it looks for the file, if the file is found it loads the image to a sprite and returns the sprite id. I create many functions like this that have helped me track down issues easily because I have them log errors.

BUT
Loading a bad image file on Android / iOS should simply show that ugly missingimage.png file with the red X so I don't think the file is the problem.
The times I have run into random crashes have almost ALWAYS been because I'm calling reference to an UDT array index which doesn't exist. AppGameKit on windows will completely ignore the error and move on most of the time. Android will crash. SO check you _TMX_Layer_Count variable. It's probably falling out of range.
Also you might want to consider having an int in the UDT dedicated to tracking the array size. I made use of this after many of these types of crashes and it saved me a lot of work later on.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Mar 2014 03:46 Edited at: 6th Mar 2014 03:46
I know the file is good because the exact same line of code works fine outside of the loop.

In my experience, typically when I get a generic application crash like this it's due to a syntax error somewhere that isn't being caught. Like just tonight, trying to assign a value to an array but my index was out of bounds. Didn\'t get an out of bounds error, simply crashed.

But I've already worked around this issue and moved on.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 6th Mar 2014 03:48
Oob errors don't appear for UDT arrays. Something I reported a long time ago

Login to post a reply

Server time is: 2024-11-25 03:50:41
Your offset time is: 2024-11-25 03:50:41