Global array of types keeps returning Null?

BlitzMax Forums/BlitzMax Programming/Global array of types keeps returning Null?

Hotcakes(Posted 2005) [#1]
A little help, if you could spare your time - firstly, a big box o' code:

Don't get too scared about all that, there's only a couple of small sections I need help with : revolving around my use of the ColourMap:ColourRegister[] Global. What I'm trying to do with it, is keep an array of red, green, blue information available to the loader method in between calls. Looking at the code up there it doesn't make any sense to do it this way, but I'll be expanding on that later. If you jump down to the "CMAP" section, what it does is this : If a ColourMap array doesn't exist (ie it's Null), it creates an array of the size of the CMAP chunk (the number of colours in the palette table) - then when it comes time to setting the values in the array, it errors out with 'trying to access field of Null object'.

Which is fine, my head isn't coping very well with all this, but I managed to figure out that each entry in the array needs initialising as well, being that it's a custom type. But if you unRem the ColourMap line in that loop, I still have problems at the bottom of the method - scroll down to the pixmap.WritePixel line. Here, again, I get complaints that I'm referencing a Null object, which I thouroughly don't understand, it was created and set when I processed the CMAP entry - why can't I access it now?

It's supposed to be Global so there shouldn't be any problems from what I can tell. Any ideas would be immensely appreciated.

Oh, if you need an example file to use this on for whatever reason, grab one at http://members.dodo.com.au/~tzuyd/bull.iff - it's a small 5x5 graphic with a palette of 16 colours.

Oh and there's every possibility that even if the ColourMap stuff was working, that the graphic would look completely corrupted, so don't worry about that ;]


TomToad(Posted 2005) [#2]
I believe you need to replace
ColourMap = New ColourRegister[cmap+1]	

with
ColourMap = ColourMap[..cmap+1]

At least that's what I do when I don't know in advance how large an array will be, and it works for me.


Hotcakes(Posted 2005) [#3]
Thanks but no thanks Tom, that didn't seem to make a difference =[

Also, since ColourMap is a Global, is there a way to view it in the debug list? I only see the Locals in there... It's probably hiding somewhere that I missed =]


Tiger(Posted 2005) [#4]
As you write, 'If a ColourMap array exists (ie it isn't Null), it creates an array of the size of the CMAP chunk...'

But when I read the code, I can see that you are doing the other way around.
You check if colormap=null, I don't know if thats the problem.


Hotcakes(Posted 2005) [#5]
Woah, I must have been tired. No, that is supposed to read 'if a ColourMap array doesn't exist (ie it is Null)'... no need to create an array if one already exists (which I realise is impossible with the code posted above)...

EDIT : Something is definately amiss here. Either something is not behaving correctly, or there's a concept hidden somewhere that I'm completely failing to grasp. Observe:
This is essentially exactly the same code as before, with the bulk of the 'working' code removed. The biggest change is that I've converted from using a global custom type array to 3 seperate global arrays of the standard Int variety. These are supposed to be Globals and empty arrays are supposed to be equal to an array of size 0. So why, then, does it complain 'Identifier not found' when it encounters the above commented lines? Am I essentially in over my head here or is something genuinely not adding up?


skidracer(Posted 2005) [#6]
Wow, I have no idea how the compiler should be parsing that, I would recomend removing the empty brackets [] from the offending lines.

As you can see from the following a null array and an array of zero elements is the same thing:

Local a[0]
Local b[1]

If Not a Print "a is null"
If Not b Print "b is null"



Hotcakes(Posted 2005) [#7]
OK so it obviously comes down to the fact I have no idea. =] Wouldn't removing the brackets denote the array to a lowly variable? I guess that doesn't cause problems when I want to create an array later on then? Anyways, thanks simon.