"Null string supplied to CheckForTranslations" (Build 3.3.0.1160)

Started by ArgyBoi, Mon 03/11/2014 23:13:38

Previous topic - Next topic

ArgyBoi

Hi guys, this error is driving me crazy. I'm just updating a ListBox, like this:

Code: ags

function lstPatterns_OnSelectionChanged(GUIControl *control)
{
  if (lstPatterns.SelectedIndex != -1)
  {
    lblName.Text = patterns[lstPatterns.SelectedIndex].name;
    lblType.Text = patterns[lstPatterns.SelectedIndex].type;
    lblDiscoverer.Text = patterns[lstPatterns.SelectedIndex].discoverer;
    lblYear.Text = patterns[lstPatterns.SelectedIndex].year;
  }
  else
  {
    lblName.Text = "- - -";
    lblType.Text = "- - -";
    lblDiscoverer.Text = "- - -";
    lblYear.Text = "- - -";
  }
}


When I click in certain list items, the game crashes with this error:



The thing is:
1) I'm not using any translations whatsoever.
2) None of the given strings are null (I manually checked).

I'm using Build 3.3.0.1160. What's going on?

Crimson Wizard

Which line in your script is highlighted when you got this error?

Quote
1) I'm not using any translations whatsoever.
It does not matter, AGS checks for existing ones all the time.

ArgyBoi

Quote from: Crimson Wizard on Mon 03/11/2014 23:20:57
Which line in your script is highlighted when you got this error?

Line 5:
Code: ags
lblName.Text = patterns[lstPatterns.SelectedIndex].name;


Crimson Wizard

Are you 100% sure they are not null?
Just to double check, this may be tested as
Code: ags

if (patterns[lstPatterns.SelectedIndex].name == null)
   Display("String is null!!!");

ArgyBoi

I've solved it. It was an array out of bounds ("patterns" array index) problem. The error message misled me, though.
Thanks anyways!

monkey0506

There should be an array index out of bounds error before any null reference error crops up. Probably worth looking into so that a more meaningful error is presented. Since this is a user-defined struct type on 3.3.0 then it's safe to assume that you're working with a static array. Working from the inside out this should be retrieving the item from the array first, accessing its "name" property second, sending that String to GetTranslation next, and then storing the result in lblName.Text... There's no reason it shouldn't be able to detect the invalid index before parsing any pointers (e.g., the String).

Crimson Wizard

Quote from: monkey_05_06 on Tue 04/11/2014 15:57:24
There should be an array index out of bounds error before any null reference error crops up. Probably worth looking into so that a more meaningful error is presented. Since this is a user-defined struct type on 3.3.0 then it's safe to assume that you're working with a static array. Working from the inside out this should be retrieving the item from the array first, accessing its "name" property second, sending that String to GetTranslation next, and then storing the result in lblName.Text... There's no reason it shouldn't be able to detect the invalid index before parsing any pointers (e.g., the String).

It does detect an invalid index.

Code: ags

struct my_s
{
	String a;
	String b;
};

my_s my_array[10];

function game_start() 
{
	int i = 10;
	Label1.Text = my_array[i].a;
}


This displays "array index out of bounds" error.

monkey0506



Gurok

I tried replicating this too, but I had similar results to CW. Interestingly, if it's a dynamic array, you get a null pointer rather than an OOB error. (Not that such an array could be initialised under 3.3.0!)

JuaniT, can you confirm that it was actually out of bounds of the array? Or have you perhaps declared more array elements than you're using? It would be nice to see the old code that was initialising the array.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Crimson Wizard

Quote from: Gurok on Wed 05/11/2014 10:17:28
I tried replicating this too, but I had similar results to CW. Interestingly, if it's a dynamic array, you get a null pointer rather than an OOB error. (Not that such an array could be initialised under 3.3.0!)
Erm... what kind of array is that? We can't have dynamic array of user structs containing managed pointers in 3.4.0 too. And Strings are managed pointers... Unless there's more compiler mistakes (roll).

ArgyBoi

Hey guys, sorry if I caused confusion with this. I'll try to explain what the problem was the best I can (or the best my poor English allows me to). This is part of my AGSLife program.

I'm using a fixed size array of a user defined structure:

Code: ags

// Pattern struct
struct Pattern
{
  String name;
  String type;
  String discoverer;
  String year;
  bool patternGrid[CELL_NUMBER];
};

// [GLOBAL] Loaded patterns
import Pattern patterns[200];
import int patternCount;


This array is loaded with Patterns saved as files (the .pat files in the game folder). At the same time, I have a ListBox containing all the patterns in the array. So, whenever the user creates a new pattern, I have to update the array AND the list, and I wanted the most recently created pattern to be selected in the ListBox, so I have to do something like this:

Code: ags

// Add the new pattern to the array
patterns[patternCount].name = txtPatternName.Text;
patterns[patternCount].type = txtPatternType.Text;
patterns[patternCount].discoverer = txtDiscoverer.Text;
patterns[patternCount].year = txtYear.Text;

// Add the new pattern item to the list
lstPatterns.AddItem(String.Format("%s", patterns[patternCount].name.Truncate(13)));

// Increase pattern count
patternCount = patternCount + 1;  

// Select the new pattern in the list
lstPatterns.SelectedIndex = lstPatterns.ItemCount - 1;
lblName.Text = patterns[lstPatterns.SelectedIndex].name;
lblType.Text = patterns[lstPatterns.SelectedIndex].type;
lblDiscoverer.Text = patterns[lstPatterns.SelectedIndex].discoverer;
lblYear.Text = patterns[lstPatterns.SelectedIndex].year;


OK, that is the working code. Before that version, I think I was increasing the array index (patternCount) in the wrong place, and that was the reason why, when something like this tried to execute:

Code: ags
lblName.Text = patterns[lstPatterns.SelectedIndex].name;


... indeed, that string IS null, because the pattern in that position was never set. The problem was that I was receiving the "Null string" error that I mentioned in the first message, not a "Out of bounds" message; wich is correct, because the array was no technically "out of bounds", but the pattern in the referenced position was never set, due to my incompetence.
I'm sorry that I don't have the "broken" code anymore, this was a small project, so I didn't use any versioning system.

Well, that's it. Again, hope I didn't generate too much confusion with my noooooooooooooob mistake. :(

Gurok

Quote from: Crimson Wizard on Wed 05/11/2014 10:30:46
Quote from: Gurok on Wed 05/11/2014 10:17:28
I tried replicating this too, but I had similar results to CW. Interestingly, if it's a dynamic array, you get a null pointer rather than an OOB error. (Not that such an array could be initialised under 3.3.0!)
Erm... what kind of array is that? We can't have dynamic array of user structs containing managed pointers in 3.4.0 too. And Strings are managed pointers... Unless there's more compiler mistakes (roll).

Under 3.3 (and presumably earlier), you can do:

Code: ags
my_s my_array[ ];


You can't initialise the array or do anything useful with it, but you can declare it.

Also, yay JuaniT. That explanation makes a whole lot more sense. Sorry for the trouble!
[img]http://7d4iqnx.gif;rWRLUuw.gi

Crimson Wizard

Quote from: Gurok on Wed 05/11/2014 11:38:49
Under 3.3 (and presumably earlier), you can do:

Code: ags
my_s my_array[ ];


You can't initialise the array or do anything useful with it, but you can declare it.
Well, of course that will cause null-pointer error, because array itself is a null pointer. ;)

But I am glad this was sorted out; I was wondering if there's a compiler mistake or something

Gurok

Quote from: Crimson Wizard on Wed 05/11/2014 11:40:01
Quote from: Gurok on Wed 05/11/2014 11:38:49
Under 3.3 (and presumably earlier), you can do:

Code: ags
my_s my_array[ ];


You can't initialise the array or do anything useful with it, but you can declare it.
Well, of course that will cause null-pointer error, because array itself is a null pointer. ;)

But I am glad this was sorted out; I was wondering if there's a compiler mistake or something

Yeah, I wasn't saying it was wrong. Just the closest I could come to replicating it before JuaniT's explanation.
[img]http://7d4iqnx.gif;rWRLUuw.gi

SMF spam blocked by CleanTalk