My Application crashes


#1

I don’t know why but my application crashes dosn’t show a CodeEditorComponent:
here’s my code:
MainSourceEditor.h
#pragma once

#include "../JuceLibraryCode/JuceHeader.h"

class MainSourceEditor  : public Component
{
public:
    MainSourceEditor();
    ~MainSourceEditor();
    
    //void paint (Graphics&) override;
    void resized () override;        // <-- Should not be override as of now
	void InitializeEditor();
private:
    //char author = "jhave21";
    //char date_initialized = "4/11/2018"
    
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainSourceEditor)    // <-- Should be changed 
};

MainSourceEditor.cpp:
#include “MainSourceEditor.h”

MainSourceEditor::MainSourceEditor(){
    setSize(600, 400);
    InitializeEditor();
}

MainSourceEditor::~MainSourceEditor()
{
}

/*
void MainSourceEditor::paint(Graphics& g){
    //g.fillAll ();

    g.setFont (Font (16.0f));
    g.setColour (Colours::white);
}
*/

void MainSourceEditor::resized(){
    /* This should be filled by statements that will be executed when the window is resized */
}

void MainSourceEditor::InitializeEditor(){
    /* I should try creating the editor once this class is called */
    
    
    // this is the document that the editor component is showing
    CodeDocument codeDocument;

    // this is a tokeniser to apply the C++ syntax highlighting
    CPlusPlusCodeTokeniser cppTokeniser;
    CodeEditorComponent* editor = new CodeEditorComponent(codeDocument, &cppTokeniser);
    editor->loadContent("8:06 PM COOL!");
}

Main.cpp
https://pastebin.com/2800gC9X (It’s quite big)

I build it with MSVC 2017


#2

The CodeEditorComponent does not make a copy from the tokenizer object pointer passed in. You need to keep it alive yourself, that is, have the tokenizer as a member variable of your MainSourceEditor class. You will probably want to do the same for the code document object too…

You are also missing the addAndMakeVisible call for the code editor component. And you are going to leak the code editor component memory…Lots of problems in the code.


#3

Guess I’ll have to find some good tutorials about JUCE GUI programming. Would you recommend anything? I can’t find good tutorials about this.


#4

In the examples/Utilities folder you can find the XMLandJSONDemo which uses a CodeEditor component to display the files.

You can also take a look at the JUCE tutorials here and focus on the “GUI” section.