Alchemy array of structure error
Feb 4, 2012 7:05 AM
Tags: none (add) #flash #alchemy #cppI use an array of structures in my project which works fine in gcc, however the alchemy version always gives 0 for values initialised in the array, but initialising a single struct in alchemy works fine, its only if it is initialised as part of the array. Here is an example which highlights my problem:
#include <string>
using namespace std;
struct inst {
int id,obj,x,y;
};
struct tile {
int id,bckid,bgx,bgy,depth,height,width,roomX,roomY;
};
struct viewstruct
{
int start_vis;
int area_x,area_y,area_w,area_h;
int port_x,port_y,port_w,port_h;
int object2follow;
int hborder,vborder,hspd,vspd;
};
struct backstruct {
int visible;
int foreground;
int background;
int area_x, area_y, horSpeed, verSpeed;
int tileHor, tileVert;
int stretch;
};
struct roomstruct
{
int id;
int order;
string name;
string cap;
int backcolor;
bool drawbackcolor;
void(*createcode)();
int width, height, spd;
int views_enabled;
viewstruct views[8];
backstruct backs[8];
int instancecount;
inst *instances;
int tilecount;
tile *tiles;
void gotome(bool=false);
};
/*
room1 initialises correctly
*/
roomstruct room1 = { 0, 0, "rm_0", "mycaption",
0xc0c0c0, -1, NULL,
640, 480, 30, false, {
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
}, { { false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
}, 0, NULL ,0, NULL };
/*
grd_rooms does not initialise correctly
*/
roomstruct grd_rooms[2] = {
//Room 0
{ 0, 0, "rm_0", "mycaption",
0xc0c0c0, -1, NULL,
640, 480, 30, false, {
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
}, { { false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
}, 0, NULL ,0, NULL },
//Room 1
{ 1, 1, "rm_1", "",
0xc0c0c0, -1, NULL,
740, 480, 30, false, {
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
{ 0, 0, 0, 640, 480, 0, 0, 640, 480, -1, 32, 32, -1, -1 },
}, { { false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
{ false, false, -1, 0, 0, 0, 0, true, true, false },
}, 0, NULL ,0, NULL },
};
int main(int argc, char* argv[])
{
printf("room1 width: %d \n",room1.width); //gives correct value
printf("grd_rooms[0] width: %d \n",grd_rooms[0].width); //wrong value
grd_rooms[0]=room1;
printf("grd_rooms[0] width: %d \n",grd_rooms[0].width); //now it has the correct value
}
Gives the correct output with normal gcc:
room1 width: 640
grd_rooms[0] width: 640
grd_rooms[0] width: 640
But not with alchemy:
room1 width: 640
grd_rooms[0] width: 0
grd_rooms[0] width: 640
This is what I use to compile the file:
g++ HelloFlash.cpp -O0 -Wall -DOSX -swc -o helloflash.swc
If you comment out the two strings in roomstruct it will give the correct output in alchemy, I have also rebuilt stl ( thanks to http://stackoverflow.com/questions/7421832/using-stl-with-alchemy/7421 834 ) and the string_test from that works.
Any information about this would be greatly appreciated.



