Segmentation error (Most likely my script)
#1

Hi, i've spent this afternoon creating a dynamic housing system for my server.
All worked fine, i could create, edit, delete etc. This was on my windows machine.
I uploaded it to my vps which runs ubuntu 10.10 x86 and tried to run it, and i received the segmentation error.
So i just tried commenting out the line that calls the function that loads my houses.
Then the server loaded up fine.
I could save houses and all that, and they'd show up but without being able to load them on startup it's a bit useless.
Un-commented the line and it wouldn't start again.
This is the code that gets called at startup, can anyone see whats wrong with it?
pawn Код:
stock AddHousesFromFile()
{
    new Str[67],hid, hprice, howned, huserid, Float:HX, Float:HY, Float:HZ, intid, Float:intX, Float:intY, Float:intZ, houseTotal, Float:vX, Float:vY, Float:vZ, Float:vA;
    mysql_query("SELECT * FROM `houses`");
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(Str))
        {
            sscanf(Str, "p<|>ddddfffdfffffff", hid, hprice, howned, huserid, HX, HY, HZ, intid, intX, intY, intZ, vX, vY, vZ, vA);
            houses[hid][houseid] = hid;
            houses[hid][owned] = howned;
            houses[hid][price] = hprice;
            houses[hid][propx] = HX;
            houses[hid][propy] = HY;
            houses[hid][propz] = HZ;
            houses[hid][propintx] = intX;
            houses[hid][propinty] = intY;
            houses[hid][propintz] = intZ;
            houses[hid][propint] = intid;
            houses[hid][vehpropx] = vX;
            houses[hid][vehpropy] = vY;
            houses[hid][vehpropz] = vZ;
            houses[hid][vehpropangle] = vA;
            SetHouseOwned(hid, 0, 0);
            houseTotal++;
        }
    }
    mysql_free_result();
    print("\n------------------------------Houses From Database-----------------------------");
    printf("                                %i houses loaded.", houseTotal);
    print("-------------------------------------------------------------------------------");
}
stock SetHouseOwned(propid, toggle, owner)
{
    if(toggle == 1)
    {
        DestroyDynamicPickup(housepickups[propid]);
        DestroyDynamicMapIcon(houseicons[propid]);
        housepickups[propid] = CreateDynamicPickup(1272, 1, houses[propid][propx], houses[propid][propy], houses[propid][propz], -1, -1, -1, 200.0);
        houseicons[propid] = CreateDynamicMapIcon(houses[propid][propx], houses[propid][propy], houses[propid][propz], 32, 0, -1, -1, -1, 500.0);
        houses[propid][ownerid] = owner;
        houses[propid][owned] = 1;
    }
    else if(toggle == 0)
    {
        DestroyDynamicPickup(housepickups[propid]);
        DestroyDynamicMapIcon(houseicons[propid]);
        housepickups[propid] = CreateDynamicPickup(1273, 1, houses[propid][propx], houses[propid][propy], houses[propid][propz], -1, -1, -1, 200.0);
        houseicons[propid] = CreateDynamicMapIcon(houses[propid][propx], houses[propid][propy], houses[propid][propz], 31, 0, -1, -1, -1, 500.0);
        houses[propid][ownerid] = 0;
        houses[propid][owned] = 0;
    }
    return 1;
}
When i looked into the server log when i uncommented it, it loads the houses, prints those 3 lines then the server stops.
Reply
#2

Move your mysql_free_result() function inside the mysql_num_rows() if statement. You're freeing query data that might not exist.
Reply
#3

Tried what you said, and it still threw it back at me.
Really wonder what it could be.
Reply
#4

You forgot to add the delimeter
pawn Код:
while(mysql_fetch_row_format(Str, "|"))
I dont know if this will fix it, but give it a try.
Reply
#5

Nope didn't like it :/

EDIT:
Just being commenting out different parts of it to see what was causing it, seems to be the whole while statement.
If i comment the while statement out it starts up.
Confused because this function is basically a copy of my faction checkpoints loader, which works fine, but with the table changed and the big list of variables in this one.

EDIT 2:
Looked into the functions for the mysql plugin im using, works now.
Changed the function that goes through the database.
Thanks for the help anyway ^^
pawn Код:
stock CreateHouses()
{
    new Str[67],hid, hprice, howned, huserid, intid, hTotal;
    new Float:HX, Float:HY, Float:HZ, Float:intX, Float:intY, Float:intZ, Float:vX, Float:vY, Float:vZ, Float:vA;
    mysql_query("SELECT * FROM `houses`");
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        mysql_fetch_row_format(Str);
        sscanf(Str, "p<|>ddddfffdfffffff", hid, hprice, howned, huserid, HX, HY, HZ, intid, intX, intY, intZ, vX, vY, vZ, vA);
        houses[hid][houseid] = hid;
        houses[hid][owned] = howned;
        houses[hid][ownerid] = huserid;
        houses[hid][price] = hprice;
        houses[hid][propx] = HX;
        houses[hid][propy] = HY;
        houses[hid][propz] = HZ;
        houses[hid][propintx] = intX;
        houses[hid][propinty] = intY;
        houses[hid][propintz] = intZ;
        houses[hid][propint] = intid;
        houses[hid][vehpropx] = vX;
        houses[hid][vehpropy] = vY;
        houses[hid][vehpropz] = vZ;
        houses[hid][vehpropangle] = vA;
        SetHouseOwned(hid, 0, 0);
        hTotal++;
    }
    mysql_free_result();
    print("\n------------------------------Houses From Database-----------------------------");
    printf("                                %i houses loaded.", hTotal);
    print("-------------------------------------------------------------------------------");
}
Reply
#6

Got this error once again, on a part of code that can't even go wrong, and it's worked for several weeks before this.
pawn Код:
mysql_connect("localhost", "root", "database", "");
That bit of code makes the server actually start up, but because the user is passworded it can't connect resulting in my server being practically dead.
But if i put the users password in, which is probably about 10 characters long into it, i get the segmentation error.
So close to scrapping this completely and start over, but i don't really want to seeing as i've spent ages on this. My first gamemode as well.
Reply
#7

Who knows a MySQL tutorial ?
Reply
#8

This isn't the place to be asking for one
I'm after help with a bloody segmentation error not a mysql tutorial.
Reply
#9

Bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)