-5

when i trying make function to set meshes, then i got error E0137. getMeshes works well. When i trying to do somethink like

RpMesh* a = header->GetMeshes();
a = newMeshes;

this too not working.

struct RpMeshHeader
{
    unsigned int   flags;
    unsigned short numMeshes;
    unsigned short serialNum;
    unsigned int   totalIndicesInMesh;
    unsigned int   firstMeshOffset;
    RpMesh *getMeshes(void) { return (RpMesh*)(this + 1); }
    void setMeshes(RpMesh* newMesh)
    {
        (RpMesh*)(this + 1)= newMesh;
    }
    bool isValidMeshId(int meshId)
    {
        return (meshId != NULL && numMeshes >= meshId);
    }
}

Whole file https://github.com/CrosRoad95/mtasa-blue/blob/f740b0d7410f33ff323cad25bf897725ad44d7d3/Client/sdk/game/RenderWare.h

1 Answers1

0

The error here is quite clear:

void setMeshes(RpMesh* newMesh)
{
    (RpMesh*)(this + 1)= newMesh;
}

error: lvalue required as left operand of assignment

the following is not an lvalue and so you cannot assign to it.

(RpMesh*)(this + 1)

The github you linked shows the setMeshes as the following

void setMeshes(RpMesh* newMeshes)
{
    RpMesh* meshes = (RpMesh*)(this + 1);
    meshes = newMeshes;
}

which is fine in terms of syntax. First you create a pointer meshes to which you assign the address of (this+1) (if this was an array, this+1 would point to the next element in the array) but with a cast!

You cast this hypothetical next element in this array of RpMeashHeader to RpMesh with a C-style cast (which afaik will default to a reinterpret_cast in this case see here for more information)

But has this memory every been allocated? This seems unsafe.

Philipp
  • 2,376
  • 5
  • 29
  • 47