Giter VIP home page Giter VIP logo

Comments (8)

rdb avatar rdb commented on May 15, 2024

Hmm, that codebase has quite strange inheritance. Why does everything virtually inherit from TypedObject? Only one base need do so; since ClickablePopup already inherits indirectly from TypedObject, for example, there's nothing to gain from a class that derives from ClickablePopup also inheriting from TypedObject.

Which class in question is interrogate erroring about, though? It would help to also see the error message itself.

from panda3d.

theclashingfritz avatar theclashingfritz commented on May 15, 2024

The error itself is "2>..\src\nametag_igate.cxx(2542): error C2385: ambiguous access of 'as_typed_object'
2> could be the 'as_typed_object' in base 'TypedObject'
2> or could be the 'as_typed_object' in base 'TypedObject'
2>..\src\nametag_igate.cxx(2542): error C3861: 'as_typed_object': identifier not found
2>..\src\nametag_igate.cxx(4028): error C2385: ambiguous access of 'as_typed_object'
2> could be the 'as_typed_object' in base 'TypedObject'
2> or could be the 'as_typed_object' in base 'TypedObject'
2>..\src\nametag_igate.cxx(4028): error C3861: 'as_typed_object': identifier not found"

and i can't get rid of TypedObject for either of the bases for Nametag2d as both bases have things that need to be published. The rest of the virtual bases are for inheritance or to prevent conflicting class usage.

from panda3d.

theclashingfritz avatar theclashingfritz commented on May 15, 2024

And both sections the error happens just in case you're curious about that

/**
 * Python function wrapper for:
 * Nametag2d &Nametag2d::operator =(Nametag2d const &tag)
 */
static PyObject *Dtool_Nametag2d_operator_86(PyObject *self, PyObject *arg) {
  Nametag2d *local_this = NULL;
  if (!Dtool_Call_ExtractThisPointer_NonConst(self, Dtool_Nametag2d, (void **)&local_this, "Nametag2d.assign")) {
    return NULL;
  }
  // 1-Nametag2d &Nametag2d::operator =(Nametag2d const &tag)
  Nametag2d const *arg_this = (Nametag2d *)DTOOL_Call_GetPointerThisClass(arg, Dtool_Ptr_Nametag2d, 1, "Nametag2d.assign", true, true);
  if (arg_this != NULL) {
    (*local_this).operator =(*arg_this);
    Nametag2d *return_value = local_this;
    if (return_value != (Nametag2d *)NULL) {
      return_value->ref();
    }
    if (Dtool_CheckErrorOccurred()) {
      if (return_value != (Nametag2d *)NULL) {
        unref_delete(return_value);
      }
      return NULL;
    }
    if (return_value == NULL) {
      Py_INCREF(Py_None);
      return Py_None;
    } else {
      return DTool_CreatePyInstanceTyped((void *)return_value, *Dtool_Ptr_Nametag2d, true, false, return_value->as_typed_object()->get_type_index());
    }
  }
  if (!_PyErr_OCCURRED()) {
    return Dtool_Raise_BadArgumentsError(
      "assign(const Nametag2d self, const Nametag2d tag)\n");
  }
  return NULL;
}
/**
 * Python function wrapper for:
 * Nametag2d *NametagGroup::get_nametag_2d(void)
 */
static PyObject *Dtool_NametagGroup_get_nametag_2d_131(PyObject *self, PyObject *) {
  NametagGroup *local_this = NULL;
  if (!Dtool_Call_ExtractThisPointer_NonConst(self, Dtool_NametagGroup, (void **)&local_this, "NametagGroup.get_nametag_2d")) {
    return NULL;
  }
  // 1-Nametag2d *NametagGroup::get_nametag_2d(void)
  Nametag2d *return_value = (*local_this).get_nametag_2d();
  if (return_value != (Nametag2d *)NULL) {
    return_value->ref();
  }
  if (Dtool_CheckErrorOccurred()) {
    if (return_value != (Nametag2d *)NULL) {
      unref_delete(return_value);
    }
    return NULL;
  }
  if (return_value == NULL) {
    Py_INCREF(Py_None);
    return Py_None;
  } else {
    return DTool_CreatePyInstanceTyped((void *)return_value, *Dtool_Ptr_Nametag2d, true, false, return_value->as_typed_object()->get_type_index());
  }
}

from panda3d.

rdb avatar rdb commented on May 15, 2024

This is not really an issue of Interrogate, but of your odd inheritance that makes the call to the inherited method as_typed_object() ambiguous. This applies to any code that calls it, including the interrogate-generated code. The compiler gets confused; since your object inherits from TypedObject several times, it won't know which version of the inherited method to pick.

(In theory, interrogate could pick a class and force a devirtualised call. But how would it know which one to pick?)

It's usually a bad idea to inherit multiple times from TypedObject. But if you must do so, you need to define a method in the class that inherits multiple times, to disambiguate the call to as_typed_object().

CollisionVisualizer is a Panda class that inherits multiple times from TypedObject, and it defines the following methods to resolve this conflict:

// To disambiguate the multiple inheritance from TypedObject.
INLINE TypedObject *as_typed_object();
INLINE const TypedObject *as_typed_object() const;

/**
* This is provided to disambiguate the typecast to TypedObject, since we have
* two TypedObjects in our inheritance chain.
*/
INLINE TypedObject *CollisionVisualizer::
as_typed_object() {
// In fact, it really doesn't matter which one we pick. Arbitrarily pick
// the one that goes through PandaNode.
return PandaNode::as_typed_object();
}
/**
* This is provided to disambiguate the typecast to TypedObject, since we have
* two TypedObjects in our inheritance chain.
*/
INLINE const TypedObject * CollisionVisualizer::
as_typed_object() const {
// In fact, it really doesn't matter which one we pick. Arbitrarily pick
// the one that goes through PandaNode.
return PandaNode::as_typed_object();
}

from panda3d.

rdb avatar rdb commented on May 15, 2024

Oh, and for the record:

and i can't get rid of TypedObject for either of the bases for Nametag2d as both bases have things that need to be published. The rest of the virtual bases are for inheritance or to prevent conflicting class usage.

You don't need to inherit from TypedObject to publish anything via Interrogate. It will wrap the types just fine without any TypedObject in your inheritance tree.

(It's only needed for dynamic upcasting; so that a method that returns a PandaNode pointer will automatically upcast to a GeomNode on the Python side if it's really a GeomNode. Even then, you only need one TypedObject in the class hierarchy; adding multiple inheritances to TypedObject will just confuse matters.)

Needing virtual inheritance is usually a sign that you may need to rethink your class hierarchy. It's a tool that should be used sparingly; I don't believe virtual inheritance is needed in any part of the Panda3D codebase.

from panda3d.

loblao avatar loblao commented on May 15, 2024

I wrote this code a few years ago. It's broken and unfinished (how did it even get leaked?). I do not recommend using it.

from panda3d.

theclashingfritz avatar theclashingfritz commented on May 15, 2024

It was public Loblao. Also i only plan on using it as a base as i slowly RE Disney's Nametags

from panda3d.

theclashingfritz avatar theclashingfritz commented on May 15, 2024

Also thanks for the help rdb. (Didn't know you didn't need a TypedObject to publish...) And the class hierarchy will now finally be able to under go some renovations as i needed that to compile to do some testing and etc.

from panda3d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.