About Store Forum Documentation Contact



Post Reply 
Having problems with Memb
Author Message
McTomas Offline
Member

Post: #1
Having problems with Memb
Hi

Is there a way to have my "Memb<Shape> _shapes" container as an attribute of my object?

Everytime I try to put it as an attribute of my object it gives me this error.

But when I put the "Memb<Shape> _shapes" at the top of my .cpp object file, the game works just fine, and Memb does it job correctly.

Probably I'm doing something wrong, but I've tried Memb<Shape>::Memb(), Memb<Shape>(), _shapes.replaceClass(Shape) in the construction object but nothing.

Don't know what else to do :S


Attached File(s) Image(s)
   
07-12-2010 01:49 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Having problems with Memb
maybe you zero the memory of the memory container or object?
Memb<Shape> memb; is ok
but after that, you can't zero it
07-12-2010 10:52 AM
Find all posts by this user Quote this message in a reply
McTomas Offline
Member

Post: #3
RE: Having problems with Memb
I don't zero it. This is my code for ship.cpp and in the Ship attributes(ship.h) I put Memb<Shape> _shapes;

Code:
/******************************************************************************/
//Memb<Shape> _shapes;
/******************************************************************************/
Ship::Ship(Vec position) {
    pos = _posInit = position;
    T.resetPos();
}

void Ship::resetPos() {
    Tri tri = Tri(Vec(-0.06,-0.06,0), Vec(0.06,-0.06,0), Vec(0,0.06,0));
    REPD(i,3) {
        _shapes.New() = Shape(tri.edge(i));
    }
}

This only works when I remove _shapes from ship.h and uncomment //Memb<Shape> _shapes; from ship.cpp

I'm confused here :S

Thanks for the reply grin
07-12-2010 01:24 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #4
RE: Having problems with Memb
what's your Ship constructor, is it properly called?
07-12-2010 01:39 PM
Find all posts by this user Quote this message in a reply
McTomas Offline
Member

Post: #5
RE: Having problems with Memb
Thank you very much wink...The problem is that I had an Ship(){} contructor that was cleaning the ship. Thanks wink
07-12-2010 03:35 PM
Find all posts by this user Quote this message in a reply
McTomas Offline
Member

Post: #6
RE: Having problems with Memb
Hi.

I noticed a problem when using Memb or Cache(in my case Fonts Cache). Probably the problem is with my coding, but it's a strange problem.

Code:
struct A {
A() { Font *font = Fonts(S+"fontA.gfx"); }
}

struct B {
B(){}
B(String name) { Font *font = Fonts(S+"font"+name+".gfx"); }
}

If I call in the code
Quote:A fontA;
fontA = A();
I get problems with pointers in the Cache Font

If I call in the code
Quote:B fontB;
fontB = B("BBB");
I got no problems.

I just want to understand this problem. Why with A I got the problems with the Fonts cache?

Thank you very much wink
(This post was last modified: 07-19-2010 11:41 PM by McTomas.)
07-19-2010 11:41 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #7
RE: Having problems with Memb
Is fontA a global variable? If so, that's probably the problem. The default constructor is being automatically called at the start of the program before the engine has been initialized.
07-20-2010 07:41 AM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #8
RE: Having problems with Memb
you can load a font after the engine has been initialized (after global function Init)
07-20-2010 12:09 PM
Find all posts by this user Quote this message in a reply
McTomas Offline
Member

Post: #9
RE: Having problems with Memb
No the fontA isn't a global variable. Thanks I understand it now wink

Just another question.

How can I implement a get to return an Memb attribute. example:

Code:
Memb<Shape> shapes;
Memb<Shape> getShapes() { return shapes; }

In the compilling he never accepts Memb to be a return type. How can I do that?

Thank again
07-20-2010 01:13 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #10
RE: Having problems with Memb
getShapes() needs to return a reference to shapes, so...

Code:
Memb<Shape> shapes;
Memb<Shape> &getShapes() { return shapes; }
07-20-2010 09:25 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #11
RE: Having problems with Memb
thanks, I should remove the 'explicit' keyword for that from the header
reference is good solution
if you want to create new memory container when returning, you can use Memc (it doesn't have explicit keyword)
I'll remove explicit for Memb for next release.
07-20-2010 09:34 PM
Find all posts by this user Quote this message in a reply
McTomas Offline
Member

Post: #12
RE: Having problems with Memb
Thank you for the explanation and the fix grin
07-20-2010 11:54 PM
Find all posts by this user Quote this message in a reply
Post Reply