Crash à l'appel d'une méthode.
Salut, je possède une classe Button, dans laquelle je défini un bouton, et quelques foncteurs pour appeler une méthode d'une interface lorsqu'on clique sur le bouton ce qui donne ceci ;
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
Button::Button(math::Vec3f position, math::Vec3f size, const Font* font, sf::String t, RenderWindow& rw) :
rw(rw),
LightComponent(position, size, size * 0.5f,false) {
background = sf::Color::White;
text.setFont(*font);
text.setString(t);
text.setColor(sf::Color::Black);
text.setPosition(position);
text.setSize(size);
rect = RectangleShape(size);
rect.setOutlineThickness(5.f);
rect.setOutlineColor(sf::Color::Black);
}
void Button::clear() {
rect.setFillColor(background);
}
void Button::setTextSize(unsigned int size) {
text.setCharacterSize(size);
}
void Button::setTextColor(sf::Color color) {
text.setColor(color);
}
void Button::draw(RenderTarget& target, RenderStates states) {
rect.setPosition(getPosition());
target.draw(rect, states);
target.draw(text, states);
}
std::string Button::getText() {
return text.getString().toAnsiString();
}
bool Button::isMouseInButton() {
physic::BoundingBox bb = getGlobalBounds();
math::Vec2f mousePos = math::Vec2f(sf::Mouse::getPosition(rw).x, sf::Mouse::getPosition(rw).y);
if (bb.isPointInside(mousePos)) {
return true;
}
return false;
}
void Button::addActionListener (ActionListener *al) {
core::FastDelegate<bool> trigger(&Button::isMouseInButton, this);
core::FastDelegate<void> slot(&ActionListener::actionPerformed,al, this);
core::Action a (core::Action::EVENT_TYPE::MOUSE_BUTTON_PRESSED_ONCE, sf::Mouse::Left);
core::Command cmd(a, trigger, slot);
getListener().connect("CBUTTONCLICKED", cmd);
} |
Cette classe hérite de LightComponent, et la classe LightComponent de la classe component, pour chaque gui on a la possibilité de la rendre in/visible et de dés/activer son contexte de gestion d'événements.
J'ai aussi ajouter une méthode que l'on peut redéfinir lorsque l'on change la visibilité ou lorsque l'on change l'état du contexte de gestion d'événements propre à la gui :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int Component::nbComponents = 0;
void Component::setEventContextActivated(bool activateEventContext) {
this->activateEventContext = activateEventContext;
onEventContextActivated(activateEventContext);
}
bool Component::isEventContextActivated() {
return activateEventContext;
}
void Component::setVisible (bool visible) {
onVisibilityChanged(visible);
this->visible = visible;
}
bool Component::isVisible() {
return visible;
}
void Component::onVisibilityChanged(bool visible) {}
void Component::onEventContextActivated(bool activate) {} |
Les méthodes onVisiblityChanged et onEventContextActivated sont virtuelle.
Mais j'ai un crash, lors de l'appel à la méthode setVisible :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void Pong::actionPerformed(gui::Button* button) {
if (button == m_bPseudo) {
std::string text = "CONNECT*"+m_taPseudo->getText();
SymEncPacket packet;
packet<<text;
Network::sendTcpPacket(packet);
std::string response = Network::waitForLastResponse("CONNECTED");
std::vector<std::string> infos = split(response, "*");
if (infos[0] == "NOTOK") {
m_pseudoUsed->setVisible(true);
} else {
m_taPseudo->setVisible(false);
m_bPseudo->setVisible(false); |
Ca crash à cette ligne-ci :
Code:
1 2
|
m_bPseudo->setVisible(false); |
Lors de l'appel de la méthode onVisibilityChanged.
Code:
1 2 3 4 5 6 7 8 9 10 11
|
#0 0xfffffffffffffff8 ?? () (??:??)
#1 0x45ee46 odfaeg::graphic::Component::setVisible(bool) () (??:??)
#2 0x43d96f Pong::actionPerformed(this=0x7fffffffe260, button=0x8a7730) (/home/laurent/Développement/Projets-c++/ODFAEGVIDEOTUTORIAL2/pong.cpp:149)
#3 0x46534d std::_Function_handler<void (odfaeg::graphic::gui::ActionListener*&, odfaeg::graphic::gui::Button*&), odfaeg::core::DynamicWrapper<void, odfaeg::graphic::gui::ActionListener, odfaeg::graphic::gui::Button*> >::_M_invoke(std::_Any_data const&, odfaeg::graphic::gui::ActionListener*&, odfaeg::graphic::gui::Button*&) () (??:??)
#4 0x43584b odfaeg::core::Listener::processEvents(this=0x8a7930) (/usr/local/include/odfaeg/Core/listener.h:161)
#5 0x435755 odfaeg::core::Listener::pushEvent(this=0x8a7930, event=...) (/usr/local/include/odfaeg/Core/listener.h:142)
#6 0x435973 odfaeg::graphic::Component::pushEvent(this=0x8a7730, event=...) (/usr/local/include/odfaeg/Graphics/component.h:19)
#7 0x436182 odfaeg::core::Application::update(this=0x7fffffffe260) (/usr/local/include/odfaeg/Core/application.h:158)
#8 0x435c67 odfaeg::core::Application::exec(this=0x7fffffffe260) (/usr/local/include/odfaeg/Core/application.h:77)
#9 0x435444 main(argc=0x1, argv=-7048) (/home/laurent/Développement/Projets-c++/ODFAEGVIDEOTUTORIAL2/main.cpp:4) |
Bon, je ne comprends vraiment pas en quoi cela peut faire crasher. D'autant plus que je ne fais que de passer une instance d'une classe dérivant de l'interface et l'instance du bouton au foncteur, et ensuite, je récupère le pointeur sur le bouton qui a été cliqué lors de la redéfinition de la méthode virtuelle pure de l'interface. (comme en java)
Et lorsque je veux rendre un bouton invisible dans cette méthode, ça crash. :/