Game Develop n'apprécie pas mes expressions d'objets

Salut 4ian,

J’ai un problème avec les expressions d’objets que je crée pour l’extension Tableaux, Game Develop refuse de les compiler :

Extrait de compilationErrors.txt C:\Users\Victor\AppData\Local\Temp/GDTemporaries/0x7589ee8events.cpp:206:91: error: static_cast from 'Object *' to 'ArrayShowerObject *' is not allowed DisplayLegacyTextOnScene(*runtimeContext->scene, (( GDNouvel_objetObjects.empty() ) ? 0 : static_cast<ArrayShowerObject*>(GDNouvel_objetObjects[0])->GetArrayToShowName()), 0, 0, std::string("255;255;255"), 0, "", std::string("")); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[code]Extrait de la déclaration du l’expression :
DECLARE_OBJECT_STR_EXPRESSION(“GetArrayShowedName”, _(“Nom du tableau affiché”), _(“Nom du tableau affiché”), _(“Tableaux”), “res/Array/arrayShower16.png”)

                                instrInfo.AddParameter("object", _("ArrayShower"), "", false);

                                instrInfo.cppCallingInformation.SetFunctionName("GetArrayToShowName").SetIncludeFile("Array/ArrayShowerObject.h");

                DECLARE_END_OBJECT_STR_EXPRESSION()[/code]

Autres infos : L’objet est ArrayShower mais la class correspondante est ArrayShowerObject.

Vois-tu un problème dans le code ?

Merci d’avance.

Ton objet en question dérive bien de Object ?
Le fichier “Array/ArrayShowerObject.h” est inclus à ce que je vois, mais à tout hasard, les gardes d’inclusion sont elles bien correctes ( Genre un copier collé qui aurait mal tourné et aurait dupliqué des gardes dans plusieurs fichiers ) ?

Il dérive bien de Object et a des gardes d’inclusions correctes… :frowning:

Tu peux me montrer le fichier d’entête ?

Voilà l’en-tête ArrayShowerObject.h :

[code]#ifndef ArrayShowerOBJECT_H
#define ArrayShowerOBJECT_H

#include “GDL/Object.h”
#include “GDL/CommonTools.h”
//#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Color.hpp>
#include
#include

class Evaluateur;
class ImageManager;
class RuntimeScene;
class Object;
class ExpressionInstruction;
class StrExpressionInstruction;
class ObjectsConcerned;
class ImageManager;
class InitialPosition;
#if defined(GD_IDE_ONLY)
class wxBitmap;
class Game;
class wxWindow;
class MainEditorCommand;
class ResourcesMergingHelper;
#endif

/**

  • Text Object
    */
    class GD_EXTENSION_API ArrayShowerObject : public Object
    {
    public :

     enum ArrayType
     {
         Array1D,
         Array2D,
         ArrayMap
     };
    
     enum BorderStyle
     {
         BorderColor,
     };
    
     enum BackgroundStyle
     {
         BackgroundNone,
         BackgroundColor,
         BackgroundImage
     };
    
     enum ArrayContentOrientation
     {
         ContentHorizontal,
         ContentVertical
     };
    
     ArrayShowerObject(std::string name_);
     virtual ~ArrayShowerObject();
     virtual ObjSPtr Clone() { return boost::shared_ptr<Object>(new ArrayShowerObject(*this));}
    
     virtual bool LoadResources(const RuntimeScene & scene, const ImageManager & imageMgr );
     virtual bool LoadRuntimeResources(const RuntimeScene & scene, const ImageManager & imageMgr );
    
     virtual bool InitializeFromInitialPosition(const InitialPosition & position);
    
     virtual bool Draw(sf::RenderWindow& main_window);
    
     #if defined(GD_IDE_ONLY)
     virtual bool DrawEdittime(sf::RenderWindow& main_window);
     virtual bool GenerateThumbnail(const Game & game, wxBitmap & thumbnail);
    
     virtual void EditObject( wxWindow* parent, Game & game_, MainEditorCommand & mainEditorCommand_ );
     virtual wxPanel * CreateInitialPositionPanel( wxWindow* parent, const Game & game_, const Scene & scene_, const InitialPosition & position );
     virtual void UpdateInitialPositionFromPanel(wxPanel * panel, InitialPosition & position);
    
     virtual void GetPropertyForDebugger (unsigned int propertyNb, string & name, string & value) const;
     virtual bool ChangeProperty(unsigned int propertyNb, string newValue);
     virtual unsigned int GetNumberOfProperties() const;
     #endif
    
     virtual void LoadFromXml(const TiXmlElement * elemScene);
     #if defined(GD_IDE_ONLY)
     virtual void SaveToXml(TiXmlElement * elem);
     #endif
    
     virtual void OnPositionChanged() {};
    
     virtual float GetWidth() const;
     virtual float GetHeight() const;
    
     virtual float GetDrawableX() const;
     virtual float GetDrawableY() const;
    
     virtual float GetCenterX() const;
     virtual float GetCenterY() const;
    
     virtual inline bool SetAngle(float newAngle) {return true;};
     virtual inline float GetAngle() const {return 0;};
    
     virtual inline void SetWidth(float newWidth) {width = newWidth;};
     virtual inline void SetHeight(float newHeight) {height = newHeight;};
    
     virtual inline std::string GetArrayToShowName() const {return arrayToShowName;};
     virtual inline void SetArrayToShowName(std::string newName) {arrayToShowName = newName;};
    
     virtual inline int GetArrayToShowType() const {return arrayToShowType;};
     virtual inline void SetArrayToShowType(int newType) {arrayToShowType = newType;};
    
     virtual inline int GetArrayOrientation() const {return arrayOrientation;};
     virtual inline void SetArrayOrientation(int newOrientation) {arrayOrientation = newOrientation;};
    
     virtual inline sf::Color GetBackgdColor() const {return backgdColor;};
     virtual inline void SetBackgdColor(sf::Color newColor) {backgdColor = newColor;};
    
     virtual inline sf::Color GetForegdColor() const {return foregdColor;};
     virtual inline void SetForegdColor(sf::Color newColor) {foregdColor = newColor;};
    
     virtual inline int GetRows() const {return rows;};
     virtual inline void SetRows(int newValue) {SetNeedingSizeUpdate(true);rows = newValue;};
    
     virtual inline int GetColumns() const {return columns;};
     virtual inline void SetColumns(int newValue) {SetNeedingSizeUpdate(true);columns = newValue;};
    
     virtual inline std::string GetRowsSizeExpression() const {return rowsSizeExpression;};
     virtual inline void SetRowsSizeExpression(std::string newStr) {rowsSizeExpression = newStr;};
    
     virtual inline std::string GetColumnsSizeExpression() const {return columnsSizeExpression;};
     virtual inline void SetColumnsSizeExpression(std::string newStr) {columnsSizeExpression = newStr;};
    
     virtual inline void SetNeedingSizeUpdate(bool need = true) {needSizeUpdate = need;};
    
     virtual inline int GetFontSize() const {return fontSize;};
     virtual inline void SetFontSize(int newSize) {fontSize = newSize;};
    
     virtual inline int GetBorderWidth() const {return borderWidth;};
     virtual inline void SetBorderWidth(int newValue) {borderWidth = newValue;};
    
     virtual inline int GetExteriorBorderWidth() const {return extBorderWidth;};
     virtual inline void SetExteriorBorderWidth(int newValue) {extBorderWidth = newValue;};
    
     virtual inline int GetMargins() const {return margins;};
     virtual inline void SetMargins(int width) {margins = width;};
    
     virtual inline sf::Color GetBorderColor() const {return borderColor;};
     virtual inline void SetBorderColor(sf::Color newColor) {borderColor = newColor;};
    
     virtual inline int GetBackgroundStyle() const {return backgroundStyle;};
     virtual inline void SetBackgroundStyle(int newStyle) {backgroundStyle = newStyle;};
    
     virtual inline std::string GetColumnsTitlesExpression() const {return columnsTitlesExpression;};
     virtual inline void SetColumnsTitlesExpression(std::string newExpr) {columnsTitlesExpression = newExpr;};
    
     virtual inline std::string GetRowsTitlesExpression() const {return rowsTitlesExpression;};
     virtual inline void SetRowsTitlesExpression(std::string newExpr) {rowsTitlesExpression = newExpr;};
    
     virtual inline bool HasRowsTitles() const {return hasRowsTitles;};
     virtual inline void SetHasRowsTitles(bool has) {hasRowsTitles = has;};
    
     virtual inline bool HasColumnsTitles() const {return hasColumnsTitles;};
     virtual inline void SetHasColumnsTitles(bool has) {hasColumnsTitles = has;};
    
     virtual inline int GetRowsOffset() const {return rowsOffset;};
     virtual inline void SetRowsOffset(int newOffset) {rowsOffset = newOffset;};
    
     virtual inline int GetColumnsOffset() const {return columnsOffset;};
     virtual inline void SetColumnsOffset(int newOffset) {columnsOffset = newOffset;};
    
     virtual int GetColumnHoveredByMouse(RuntimeScene &scene);
     virtual int GetRowHoveredByMouse(RuntimeScene &scene);
    
     float GetXOfColumn(int n);
     float GetYOfRow(int n);
    
     std::string frontTextureName;
     std::string topTextureName;
     std::string bottomTextureName;
     std::string leftTextureName;
     std::string rightTextureName;
     std::string backTextureName;
    
     //Conditions
    
     //bool CondArrayToShowName( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     //bool CondRowCount( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     //bool CondColumnCount( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     //Les deux conditions de collision avec un objet sont dans ArrayConditions.cpp
    
     //bool CondRowMouse( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     //bool CondColumnMouse( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
    
     //bool CondColumnTitle( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     //bool CondRowTitle( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
    
     //bool CondColumnOffset( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     //bool CondRowOffset( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     /*bool CondYaw( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     bool CondPitch( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     bool CondRoll( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & condition );
     */
    
     //Actions
     //bool ActChangeArrayToShowName( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     //bool ActChangeRowCount( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     //bool ActChangeColumnCount( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
    
     //bool ActChangeColumnTitle( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     //bool ActChangeRowTitle( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
    
     //bool ActChangeColumnOffset( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     //bool ActChangeRowOffset( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     /*bool ActDepth( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     bool ActZPosition( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     bool ActYaw( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     bool ActPitch( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );
     bool ActRoll( RuntimeScene & scene, ObjectsConcerned & objectsConcerned, const Instruction & action );*/
    
     //Expressions
     //std::string ExpGetArrayToShowName( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const StrExpressionInstruction & exprInstruction );
     //double ExpGetRowMouse( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
     //double ExpGetColumnMouse( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
    
     //double ExpGetRowCount( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
     //double ExpGetColumnCount( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
    
     //double ExpGetRowObject( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
     //double ExpGetColumnObject( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
    
     //std::string ExpGetColumnTitle( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const StrExpressionInstruction & exprInstruction );
     //std::string ExpGetRowTitle( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const StrExpressionInstruction & exprInstruction );
    
     //double ExpGetColumnOffset( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
     //double ExpGetRowOffset( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
     /*double ExpGetPitch( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
     double ExpGetRoll( const RuntimeScene & scene, ObjectsConcerned & objectsConcerned, ObjSPtr obj1, ObjSPtr obj2, const ExpressionInstruction & exprInstruction );
    

*/
private:

    const RuntimeScene *actualScene;

    float width;
    float height;

    int fontSize;

    std::string arrayToShowName;
    int arrayToShowType;
    int arrayOrientation;

    sf::Color backgdColor;
    int backgroundStyle;

    sf::Color foregdColor;

    sf::Color borderColor;
    int borderWidth;
    int extBorderWidth;

    int margins;

    int rows;
    int columns;
    int rowsOffset;
    int columnsOffset;

    //Tailles des colonnes et lignes
    std::string rowsSizeExpression;
    std::string columnsSizeExpression;
    std::vector<float> rowsSize;
    std::vector<float> columnsSize;

    //Headers du tableau
    std::string columnsTitlesExpression;
    std::string rowsTitlesExpression;
    std::vector<std::string> columnsTitles;
    std::vector<std::string> rowsTitles;


    int borderStyle;

    void UpdateSize();
    void UpdateTitles();
    //void GenerateColumnsSize(sf::RenderWindow& main_window);
    //void GenerateRowsSize(sf::RenderWindow& main_window);

    bool hasColumnsTitles;
    bool hasRowsTitles;

    inline void DrawArrayBorder(sf::RenderWindow& window);
    inline void DrawArrayBackground(sf::RenderWindow& window);
    inline void DrawArrayTitles(sf::RenderWindow& window);
    inline void DrawArrayContent(sf::RenderWindow& window);

    inline void DrawTexta(sf::RenderWindow& window,
                         std::string text,
                         float PosX,
                         float PosY);

    bool needSizeUpdate;
    bool needTitlesUpdate;

};

void GD_EXTENSION_API DestroyArrayShowerObject(Object * object);
Object * GD_EXTENSION_API CreateArrayShowerObject(std::string name);

#endif // ArrayShowerOBJECT_H
[/code]

Essaie avec un reinterpret_cast, si c’est toi victor qui fais la conversion.
Je me suis renseigné ici :
siteduzero.com/tutoriel-3-10 … types.html
dans la partie “La réinterprétation des données”.

reinterpret_cast = mauvaise idée 99,9% du temps.

Le static_cast est généré par Game Develop et est censé très bien fonctionner car ArrayShowerObject est une classe dérivée d’Object.

C’est un problème de hiérarchie des classes ou un problème de syntaxe de code C++ ?

Le code généré ne semble pas poser de problème du point de vue syntaxe.

Le problème est résolu.

L’erreur est la conséquence de deux autres erreurs (oublie de l’inclusion de string, ce qui ne gênait pas MinGW, mais Clang…).

Si tu as oublié un string, c’est pas dans ton header alors. On n’aurait donc pas pu t’aider… Mais c’est très bien que ça marche. La prochaine fois, n’oublie pas de mettre un string ! :laughing:

EDIT : Je vois… J’arrête les blagues pas marrantes.

:laughing:

Par contre, Game Develop plante pendant l’exécution de la scène si l’expression utilise un objet qui existe sur le scène mais qui n’est pas placé dessus.

Tu veux dire un objet qui fait partie de la liste des objets de la scène qui n’est pas sur la scène ? Ca te le fait pour n’importe quel type d’objets ou seulement pour tes types d’objets (je veux dire seulement avec tes tableaux) ?

EDIT : Non, ça le fait pour toutes les expressions de texte.