Salut! J'essaie d'appeler la fonction insert de la classe std::string pour insérer du texte dans un fichier cpp.
Voici le contenu du fichier cpp et donc de ma std::string.
Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include "/home/laurent/Développement/Projets-c++/ODFAEGCREATOR/test/test.hpp"
using namespace odfaeg::graphic;
test::test(sf::VideoMode vm, std::string title) : 
Application (vm, title, sf::Style::Resize|sf::Style::Close, sf::ContextSettings(0, 0, 0, 3, 0)) {
}
void test::onLoad() {
}
void test::onInit() {
}
void test::onRender(RenderComponentManager *cm) {
}
void test::onDisplay(RenderWindow* window) {
   if (&getRenderWindow() == window) {
       for (unsigned int i = 0; i < drawables.size(); i++) {
           window->draw(*drawable[i]);
       }
   }
}
void test::onUpdate (RenderWindow* window, sf::Event& event) {
 if (&getRenderWindow() == window && event.type == sf::Event::Closed) {
  stop();
 }
}
void test::onExec () {
}
Voici l'endroit ou ça crash :
Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
if (item->getText() == "Rectangle shape") {
        std::unique_ptr<RectangleShape> shape = std::make_unique<RectangleShape>(Vec3f(100, 50, 0));
        shape->setPosition(cursor.getPosition());
        displayInfos(shape.get());
        selectedObject = shape.get();
        shapes.push_back(std::move(shape));
        unsigned int pos = cppAppliContent.find("onInit() {");
        pos += 11;
        cppAppliContent.insert(pos,"std::unique_ptr<sf::RectangleShape> shape"+conversionIntString(shape->getId())+" = std::make_unique<RectangleShape>(Vec3f(100, 50, 0));\n"
                                   "drawables.push_back(std::move(shape));\n");
        std::cout<<"file content : "<<cppAppliContent<<std::endl;
    }

std::find me trouve bien la position du premier caractère, j'ajoute 11 car je veux insérer le texte à la fin de la chaîne recherchée.
mais à l'appel de la fonction insert, ça crash, voici ce que m'affiche le débugeur.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
#0 0x8059c57	ODFAEGCreator::actionPerformed(this=0xbffef558, item=0x838bc38) (/home/laurent/Développement/Projets-c++/ODFAEGCREATOR/application.cpp:479)
#1 0x8100a70	odfaeg::core::DynamicWrapper<void, odfaeg::graphic::gui::MenuItemListener, odfaeg::graphic::gui::MenuItem*>::operator()<odfaeg::graphic::gui::MenuItemListener<odfaeg::graphic::gui::MenuItem*&> >(this=0x8388098, o=0xbffef5b0) (/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Graphics/GUI/../../../../include/odfaeg/Graphics/GUI/../../Math/../Core/fastDelegate.h:309)
#2 0x810041c	std::_Function_handler<void (odfaeg::graphic::gui::MenuItemListener*&, odfaeg::graphic::gui::MenuItem*&), odfaeg::core::DynamicWrapper<void, odfaeg::graphic::gui::MenuItemListener<odfaeg::graphic::gui::MenuItem*> > >::_M_invoke(std::_Any_data const&, odfaeg::graphic::gui::MenuItemListener*&, odfaeg::graphic::gui::MenuItem*&)(__functor=..., __args#0=@0x836509c: 0xbffef5b0, __args#1=@0x838808c: 0x838bc38) (/usr/include/c++/4.9/functional:2039)
#3 0x810202c	std::function<void (odfaeg::graphic::gui::MenuItemListener*&, odfaeg::graphic::gui::MenuItem*&)>::operator()(odfaeg::graphic::gui::MenuItemListener*&, odfaeg::graphic::gui::MenuItem*&) const(this=0x8b5efa4, __args#0=@0x836509c: 0xbffef5b0, __args#1=@0x838808c: 0x838bc38) (/usr/include/c++/4.9/functional:2440)
#4 0x810150d	odfaeg::core::FastDelegateImpl<void, odfaeg::graphic::gui::MenuItemListener*, odfaeg::graphic::gui::MenuItem*>::call<0u, 1u, void*&, void*&, void*&, void*&>(this=0x8b5efa0) (/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Graphics/GUI/../../../../include/odfaeg/Graphics/GUI/../../Math/../Core/fastDelegate.h:480)
#5 0x8100e12	odfaeg::core::FastDelegateImpl<void, odfaeg::graphic::gui::MenuItemListener*, odfaeg::graphic::gui::MenuItem*>::operator() (this=0x8b5efa0, p0=0x0, p1=0x0, p2=0x0, p3=0x0) (/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Graphics/GUI/../../../../include/odfaeg/Graphics/GUI/../../Math/../Core/fastDelegate.h:449)
#6 0x8080a22	odfaeg::core::FastDelegate<void>::operator()<>() const(this=0x8b5ee00) (/usr/local/include/odfaeg/Core/fastDelegate.h:552)
#7 0x8142601	odfaeg::core::Command::operator() (this=0x8b5edfc) (/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Core/command.cpp:89)
#8 0x8096a9a	odfaeg::core::Listener::processEvents(this=0x838bde4) (/usr/local/include/odfaeg/Core/listener.h:127)
#9 0x80e98f1	odfaeg::graphic::LightComponent::processEvents(this=0x838bc38) (/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Graphics/GUI/../../../../include/odfaeg/Graphics/GUI/../lightComponent.h:107)
#10 0x80cf8b0	odfaeg::graphic::RenderComponentManager::updateComponents(this=0x82ae278) (/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Graphics/renderComponentManager.cpp:116)
#11 0x8097047	odfaeg::core::Application::render(this=0xbffef558) (/usr/local/include/odfaeg/Core/application.h:130)
#12 0x8096db2	odfaeg::core::Application::exec(this=0xbffef558) (/usr/local/include/odfaeg/Core/application.h:82)
#13 0x8095ec6	main(argc=1, argv=0xbffff644) (/home/laurent/Développement/Projets-c++/ODFAEGCREATOR/main.cpp:10)
Bref, je ne comprend pas pourquoi ça crash, théoriquement il devrait m'insérer la chaîne de caractère sans problème.