crosire / blink

A tool which allows you to edit source code of any MSVC C++ project live at runtime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get it to work?

tim3385 opened this issue · comments

Thanks for your great work first!
I try blink with the "example_glfw_opengl3" project from ImGui examples. But it can't work.

All code and project of blink and imgui examples are clone from github repo just now and I didn't change anything. I use VS2017 with Windows SDK Version 10.0.17763.0 on Windows10. I did the following steps:

s1 Build example_glfw_opengl3 Debug|Win32.
s2 Build blink Debug|x86 and copy blink.exe into "imgui\examples\example_glfw_opengl3\Debug" directory.
s3 Open windows's cmd console and enter "imgui\examples\example_glfw_opengl3\Debug" where the example_glfw_opengl3.exe is in.
s4 Invoke "blink example_glfw_opengl3.exe" in the console. example_glfw_opengl3.exe got to run.

D:\lab\imgui\examples\example_glfw_opengl3\Debug>blink example_glfw_opengl3.exe Launching in target application ... Entry point was written to address 07B30000 Reading PE import directory ... Reading PE debug info directory ... Found program debug database: D:\lab\imgui\examples\example_glfw_opengl3\Debug\example_glfw_opengl3.pdb Found source file: d:\lab\imgui\examples\example_glfw_opengl3\main.cpp Found source file: d:\lab\imgui\examples\imgui_impl_opengl3.cpp Found source file: d:\lab\imgui\examples\imgui_impl_glfw.cpp Found source file: d:\lab\imgui\imgui_widgets.cpp Found source file: d:\lab\imgui\imgui_draw.cpp Found source file: d:\lab\imgui\imgui_demo.cpp Found source file: d:\lab\imgui\imgui.cpp Starting compiler process ... Started process with PID 137948 Starting file system watcher for 'd:\lab\imgui' ...

Yes, as you see, everything seems to be right.

s5 When I modify some code in main.cpp of example_glfw_opengl3, such as I modify "ImGui::Begin("Hello, world!");" to be "ImGui::Begin("Hello, blink!");", I get the console log info in console:

Detected modification to: d:\lab\imgui\examples\example_glfw_opengl3\main.cpp Finished compiling "d:\lab\imgui\examples\example_glfw_opengl3\main.obj" with code 0. Successfully linked object file into executable image.

Everything seems to be right too. But the result could be seen in ImGUI rendering window.
I also try run blink in VS debug mode and set the working directory and Command Arguments to point to imgui_impl_opengl3.

The function or method you're changing must be executed repeatedly, because it will be "changed" only when you enter it the next time. You're stuck in original main function. You can change it like that:

void update()
{
    ...
    ImGui::Begin("Hello, world!");
    ...
}

int main(int, char**)
{
    ...
    // Main loop
    while (!glfwWindowShouldClose(window))
    {
        update();
    }
    ...
}

Yes, of course. I know it. But it not works yet. This is the sample codes(from official example "example_glfw_opengl3/main.cpp" with my little modify) :

...
   // Main loop
    while (!glfwWindowShouldClose(window))
    {
            ...
            ImGui::Begin("Hello, world!");
            ImGui::Begin("Hello, blink!");
            ...
    }
...

Thank you for your quick reply.

You are misunderstanding things. blink causes a change you do to a function to become effective the next time the function is called. The main function is only called once at application startup and then not again. So any changes inside the main function won't be visible. For changes to become visible you have to do them in a function that is actually called repeatedly. As was explained above this can be achieved by doing the following:

void update() // Do changes inside this function
{
    glfwPollEvents();

    // Start the Dear ImGui frame
    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();
    ...
    ImGui::Begin("Hello, world!");
    ...
    glfwSwapBuffers(window);
}

int main(int, char**)
{
    ...
    // Main loop
    while (!glfwWindowShouldClose(window))
    {
        update(); // This function is now called repeatedly, so changes get visible the next time it is called after blink has loaded your changes
    }
    ...
}

This is usually the case in applications. There are rare cases in which all code is inside the main function, those samples being one of those cases.

I get the key point. It works and very cool!
Thank you very much.

Makes me wonder how it deals with inlining and/or changes to header files.