-1

I get this error when i try to compile my code:

Internal compiler error: Stack too deep, try removing local variables.

How could i get around this issue, I though the stack could be at least 16 level deep ? How is mine too deep ?!

contract ZonesFactory {
    address[] zones;
    event LogCreatedZone(address indexed hsAddr, string name, string P1Lon, string P1Lat, string P2Lon, string P2Lat, string P3Lon, string P3Lat, string P4Lon, string P4Lat);

    function add(string name, string P1Lon, string P1Lat, string P2Lon, string P2Lat, string P3Lon, string P3Lat, string P4Lon, string P4Lat) public returns(address) {
        zoneObject newZone = new zoneObject(name, P1Lon, P1Lat, P2Lon, P2Lat, P3Lon, P3Lat, P4Lon, P3Lat);
        zones.push(newZone);
        LogCreatedZone(newZone,name, P1Lon, P1Lat, P2Lon, P2Lat, P3Lon, P3Lat, P4Lon, P3Lat);
        return newZone;
    }

    function getOrgAtIndex(uint index) public constant returns(address org){
        return zones[index];
    }

    function getOrganizationCount() public constant returns(uint count) {
        return zones.length;
    }
}

contract zoneObject {

    struct LonLat {
        string P1Lon;
        string P1Lat;
        string P2Lon; 
        string P2Lat; 
        string P3Lon; 
        string P3Lat; 
        string P4Lon; 
        string P4Lat;
    }

    LonLat public lonLat;

    string public name;

    function zoneObject (string name, string P1Lon, string P1Lat, string P2Lon, string P2Lat, string P3Lon, string P3Lat, string P4Lon, string P4Lat){
        name = name;
        lonLat.P1Lon = P1Lon;
        lonLat.P1Lat = P1Lat;
        lonLat.P2Lon = P2Lon;
        lonLat.P2Lat = P1Lat;
        lonLat.P3Lon = P3Lon;
        lonLat.P3Lat = P3Lat;
        lonLat.P4Lon = P4Lon;
        lonLat.P4Lat = P4Lat;
    }

    function getDetails() public constant returns (string, string, string, string, string, string, string, string, string){
        return (name, lonLat.P1Lon, lonLat.P1Lat, lonLat.P2Lon, lonLat.P2Lat, lonLat.P3Lon, lonLat.P3Lat, lonLat.P4Lon, lonLat.P4Lat);
    }
}

EDIT

I have tried with the following code thinking that makin my points into a seperact contract would help but it just doesn't, please help:

contract ZonesFactory {
    address[] zones;
    event LogCreatedZone(address indexed hsAddr, string name, string P1Lon, string P1Lat, string P2Lon, string P2Lat, string P3Lon, string P3Lat, string P4Lon, string P4Lat);

    function add(string name, string P1Lon, string P1Lat, string P2Lon, string P2Lat, string P3Lon, string P3Lat, string P4Lon, string P4Lat) public returns(address) {
        zoneObject newZone = new zoneObject(name, P1Lon, P1Lat, P2Lon, P2Lat, P3Lon, P3Lat, P4Lon, P3Lat);
        zones.push(newZone);
        LogCreatedZone(newZone,name, P1Lon, P1Lat, P2Lon, P2Lat, P3Lon, P3Lat, P4Lon, P3Lat);
        return newZone;
    }

    function getOrgAtIndex(uint index) public constant returns(address org){
        return zones[index];
    }

    function getOrganizationCount() public constant returns(uint count) {
        return zones.length;
    }
}

contract zoneObject {

    struct PointCoords {
        pointObject P1Coords;
        pointObject P2Coords; 
        pointObject P3Coords; 
        pointObject P4Coords; 
    }

    PointCoords public pointsCoords;
    address[] public patients;
    string public name;

    function zoneObject (string name, string P1Lon, string P1Lat, string P2Lon, string P2Lat, string P3Lon, string P3Lat, string P4Lon, string P4Lat){
        name = name;
        pointsCoords.P1Coords = new pointObject(P1Lon, P1Lat);
        pointsCoords.P2Coords = new pointObject(P2Lon, P2Lat);
        pointsCoords.P3Coords = new pointObject(P3Lon, P3Lat);
        pointsCoords.P4Coords = new pointObject(P4Lon, P4Lat);
    }

    function addPatient(address patientAddress){
        patients.push(patientAddress);
    }

    function getDetails() public constant returns (string, address, address, address, address){
        return (name, pointsCoords.P1Coords pointsCoords.P2Coords, pointsCoords.P3Coords, pointsCoords.P4Coords);
    }

    function removePatient(address patient){
        if(isContract(patient)){
            for (uint i = 0; i<patients.length-1; i++){
                if(patients[i] == patient){
                    delete patients[i];
                }
            }
        }
    }

    function isContract(address addr) returns (bool) {
        uint size;
        assembly { size := extcodesize(addr) }
        return size > 0;
    }
}

contract pointObject{
    string public Lat;
    string public Lon;

    function pointObject (string Lon, string Lat){
        Lat = Lat;
        Lon = Lon;
    }
}
1

I haven't waded through all the code but the widespread use of string in the interface stood out, so I tried replacing them all with bytes32 and got a successful compile right away.

contract ZonesFactory {
    address[] zones;
    event LogCreatedZone(address indexed hsAddr, bytes32 name, bytes32 P1Lon, bytes32 P1Lat, bytes32 P2Lon, bytes32 P2Lat, bytes32 P3Lon, bytes32 P3Lat, bytes32 P4Lon, bytes32 P4Lat);

    function add(bytes32 name, bytes32 P1Lon, bytes32 P1Lat, bytes32 P2Lon, bytes32 P2Lat, bytes32 P3Lon, bytes32 P3Lat, bytes32 P4Lon, bytes32 P4Lat) public returns(address) {
        zoneObject newZone = new zoneObject(name, P1Lon, P1Lat, P2Lon, P2Lat, P3Lon, P3Lat, P4Lon, P3Lat);
        zones.push(newZone);
        LogCreatedZone(newZone,name, P1Lon, P1Lat, P2Lon, P2Lat, P3Lon, P3Lat, P4Lon, P3Lat);
        return newZone;
    }

    function getOrgAtIndex(uint index) public constant returns(address org){
        return zones[index];
    }

    function getOrganizationCount() public constant returns(uint count) {
        return zones.length;
    }
}

contract zoneObject {

    struct LonLat {
        bytes32 P1Lon;
        bytes32 P1Lat;
        bytes32 P2Lon; 
        bytes32 P2Lat; 
        bytes32 P3Lon; 
        bytes32 P3Lat; 
        bytes32 P4Lon; 
        bytes32 P4Lat;
    }

    LonLat public lonLat;

    bytes32 public name;

    function zoneObject (bytes32 name, bytes32 P1Lon, bytes32 P1Lat, bytes32 P2Lon, bytes32 P2Lat, bytes32 P3Lon, bytes32 P3Lat, bytes32 P4Lon, bytes32 P4Lat){
        name = name;
        lonLat.P1Lon = P1Lon;
        lonLat.P1Lat = P1Lat;
        lonLat.P2Lon = P2Lon;
        lonLat.P2Lat = P1Lat;
        lonLat.P3Lon = P3Lon;
        lonLat.P3Lat = P3Lat;
        lonLat.P4Lon = P4Lon;
        lonLat.P4Lat = P4Lat;
    }

    function getDetails() public constant returns (bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32, bytes32){
        return (name, lonLat.P1Lon, lonLat.P1Lat, lonLat.P2Lon, lonLat.P2Lat, lonLat.P3Lon, lonLat.P3Lat, lonLat.P4Lon, lonLat.P4Lat);
    }
}

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.