Possible bug?

Posted By: RyuMaster

Possible bug? - 09/07/08 13:34

I'm working on function witch creates panels at runtime.


Quote:
LEVEL point1; // structure
main ()
...
populate_panels(point1); //pass it to function
...


Quote:
function populate_panels(LEVEL* leveldata)
{

var i;
for (i=0; i<leveldata->overlays; i++) //Lets create as many overlays as needed
{

if(leveldata.visibility[i] == 1) //if visibility 1 then proceed
{

overlay[i] = pan_create("bmap = leveldata.filename[i];pos_x = leveldata.posy[i];pos_y=leveldata.posy[i]; flags=VISIBLE;",2);
}

}

}


leveldata is sturuct witch contains all the info.

I try to debug using this:

Quote:
printf("my_var: %.3f",(int)i);


Struct has 13 panels, and it cycles 13 times, and on every frame I get "i" variable + 1; So, basically, leveldata->overlays successfully gets "13" value from point 1 struct.
But, for sample, if I try this:

Quote:
printf("my_var: %.3f",(int)leveldata->overlays);


I get "0", but not "13";

Why is that so? And, afcourse, all parameters at function pan_create are "0" as well. But, for instance,

Quote:
if(leveldata.visibility[i] == 1)

this part of code is "1", because on every loop cycle I can see debugger passing through this point. So it DO get parameters from point1.

And just do not get what is wrong.

Loops and if..else acts like there are parameter in leveldata, but printf or pan_create do not get them at all.



Posted By: testDummy

Re: Possible bug? - 09/07/08 14:15

Code:
function populate_panels(LEVEL* leveldata)
{
	var i;
	for (i=0; i<leveldata->overlays; i++) //Lets create as many overlays as needed
	{
		if(leveldata->visibility[i] == 1) //if visibility 1 then proceed
		{
			//overlay[i] = pan_create("bmap = leveldata.filename[i];pos_x = leveldata.posy[x];pos_y=leveldata.posy[i]; flags=VISIBLE;",2);
			overlay[i] = pan_create("pos_x = 0; flags=VISIBLE;", 2);
			overlay[i]->bmap = leveldata->filename[i];
			overlay[i]->pos_x = leveldata->posx[i];  // i was x (above)
			overlay[i]->pos_y = leveldata->posy[i];
		}
	}
}

Posted By: RyuMaster

Re: Possible bug? - 09/07/08 14:46

Thanks for reply! But with such approach I get error on this line:

overlay[i]->bmap = leveldata->filename[i];

bmap is not member of a 'function'.

Probably oerlay[i] is not received as correcot pointer?
I var it as var* overlay[maxoverlays]; at the top.
Should it be something like PANEL* overlay[maxoverlays]? (this one causes engine to crash after very start)
Posted By: EvilSOB

Re: Possible bug? - 09/07/08 15:39

How is your struct currently defined? And do you "zero()" it before use?

Ive put this code together based on this post and your struct one but they dont seem to mesh.
So Ive made some assumptions and done this.
Code:
#define maxoverlays 40

typedef struct { 
   int       overlays; //How many overlays used 
   PANEL*    overlay[maxoverlays];    //Pointer to each Overlay
   int       posx[maxoverlays];       //Its position on the map
   int       posy[maxoverlays];       // "     "      "  "   "
   int       visibility[maxoverlays]; //Overlays visibility setting
   char*     filename[maxoverlays];   //Name of panels BMAP file
   char*     background;              //Name of background BMAP file
} LEVEL;

LEVEL point1; // structure

function populate_panels(LEVEL* leveldata)
{
   var i;
   for (i=0; i<leveldata.overlays; i++) //Lets create as many overlays as needed
   {
      if(leveldata.visibility[i] == 1) //if visibility of this overlay is 1 then proceed 
      {
         STRING* BuildString = str_create("");
         str_cat(BuildString,"bmap = ");   
            str_cat(BuildString,leveldata.filename[i]);   
            str_cat(BuildString,";  ");   
         str_cat_num(BuildString,"pos_x = %.0f;  ",leveldata.posx[i]);   
         str_cat_num(BuildString,"pos_y = %.0f;  ",leveldata.posy[i]);   
         str_cat(BuildString,"flags = VISIBLE;");
         leveldata.overlay[i] = pan_create(_chr(BuildString),2);
      }
   }
}


   ...
   zero(point1);       //first time use zero to clear potential junk data
   point1.overlays=13;
   // assume build/load overlay filenames etc here
   ...
   populate_panels(point1); //pass it to function
   ...

Now, if your struct has changed from what Ive "assumed", let me know what it is and I'll look again.
Theres not enough info in this thead at the moment for me to figure out any more.

PS the weird BuildString thing you'll see before the pan_create is because the
pan_create statement WILL NOT take variables from an array. The resulting panel is
only half populated. I fell in this hole hard recently, and Im still sore.
So the BuildString creates a string containing the DATA from the array variables and builds
the panel based on that.
Posted By: RyuMaster

Re: Possible bug? - 09/07/08 16:58

WOW! It actually works! I can express how thankfull I am. I think such things should be in the manual, it was impossible for me to guess what was goig on.
Posted By: RyuMaster

Re: Possible bug? - 12/26/08 18:02

I'm stuck at some point and do not know what to do...
I load and store images in BMAP pointer array.

Quote:
BMAP* overlaybmaps[currentdex] = bmap_create(path);


At some point, I need to pass it to the panel's BuildString.
If I pass simple BMAP*, like this,

Quote:
str_cat(BuildString,"BMAPPOINTERHERE;");


it works.

But if as BMAP pointer array, like

Quote:
str_cat(BuildString,"BMAPPOINTERHERE[5];");


it is not working no matter what.

Is it supposed to be this way? I have tried many combinations, using str_cat_num as well. The worst part - I can not think of any workaround,
I need to use BMAP* array for my blitting function.
Posted By: Nidhogg

Re: Possible bug? - 12/26/08 23:09

Please check for syntax or spelling errors, Also lite-c is case sensitive.

At a quick glance I noticed str_cat(BuildString,"BMAPPOINTERHERE[5];");
which could be str_cat(BuildString,"BMAPPOINTERHERE[5]");

Also I could be wrong but I think you need to convert BMAPPOINTERHERE[5]
or maybe even try without the ".

Hope this helps.
Posted By: Gordon

Re: Possible bug? - 12/27/08 08:04

Simple solution to this problem:

Code:
  str_cpy(BuildString, "bmap = NULL;");
  str_cat_num (BuildString, "size_x = %4.0f",bmap_width(overlaybmaps[currentdex]));
  str_cat_num (BuildString, "size_y = %4.0f",bmap_height(overlaybmaps[currentdex]));
 //what ever else you need for the panel here
  MyPan = pan_create(BuildString,42);
  MyPan.bmap = overlaybmaps[currentdex];

© 2024 lite-C Forums