0

I am doing a basic cinder application in Visual Studio. It is a particle generation (loosely following the online Hello Cinder guide. In debug mode it always works. In release configuration however, it sometimes does not generate any particle.

My best guess is there is UB somewhere, the problem is that it is really hard to detect. Small, seemingly unrelated changes can trigger or untrigger this.

For instance, changing in function draw:

spatial_.speed_ += 0.1f * ci::Vec2f(cos(noise * 15.0f), sin(noise * 15.0f));
//                ^^^^^
//                this value

any constant value other than 1.0f or the absence of the constant value will cause no particle to be generated. How can a change in the function draw affect the code in the function update (where I generate the particles). I know they are not generated at all because I display a particle count.

All sorts of these kind of changes all over the program cause this (like changing constants, changing parameter types from value to reference, adding or removing line that outputs to console()).

I don’t want you guys to debug my code, that’s why I didn’t put code here.
I am just lost on how to deal with this. My question is how should I proceed to diagnose the bug? What are my options, what steps do I have to take from here?

The problems I am facing:

  • I have no idea where the bug is in the whole code.
  • In debug mode everything works fine
  • I can’t debug in release mode (debugging information for ***.exe cannot be found or does not match. Binary was not build with debug information) and any break points are whited out in the GUI with the tooltip the breakpoint will not be currently hit (no symbols have been loaded for this document)
  • I can’t debug by printing output because adding the code to display output will make the program work. (How ironic is this?)
  • In release mode even if I get it to work (by trial and error, adding/removing lines), if I don’t identify the problem, there is nothing to say that changing something somewhere else will break the code again.

Update:

  • CppCheck reports no problems. I’ve manually double checked for uninitialized members/variables.
  • I’ve been trying to isolate this thing. The problem is that ANY modification I do will cause the particles to be generated. If I change any code in the draw function the particles will be generated. If I delete to code for the size of the particles the particles will be generated. If I delete the code for the motion, the particles will be generated. If I delete the code for drawing the particles, the particles will be generated. If I delete the code for the initial position of the particles, the particles will be generated, if I delete the code that removes the dead particles, the particles get generated. The only thing that I found it maintains the fault is if I change the fps settings, so yeah, I know that setting the fps is not causing the problem, so hurray.
bolov
  • 72,283
  • 15
  • 145
  • 224
  • 1
    Have you considered unit tests? – Kerrek SB Jul 02 '14 at 13:48
  • @KerrekSB I’ve never worked with unit tests (I am a student). How wold that work? – bolov Jul 02 '14 at 13:49
  • Step 1 is to isolate the behaviour into a small complete program – David Heffernan Jul 02 '14 at 13:49
  • Try changing your release build settings; in Visual Studio, you can build a release build with debug info and you can change your optimization levels. If you try with no optimization in a release build, do you still get the issues? – Eric Finn Jul 02 '14 at 13:51
  • 2
    @bolov: Buy a book or five on the subject, learn a testing framework or three, and start writing some projects in a test-driven way. – Kerrek SB Jul 02 '14 at 13:51
  • @DavidHeffernan that’s what I would normally do. However here the problem is that I change something small the behaviour is correct. If I change something small somewhere else, the behaviour is incorrect again. So I rly dont’t know to isolate this. – bolov Jul 02 '14 at 13:52
  • I guess you need to keep trying to isolate this – David Heffernan Jul 02 '14 at 13:57
  • It seems to work fine with optimisation disables, Optimise size O1 and full optimization Ox; only in optimize speed O2 the program doesn’t work. – bolov Jul 02 '14 at 13:58
  • if you haven't already, enable all warnings, and check for uninitialized variables – mark Jul 02 '14 at 13:58
  • 1
    Try static C++ code analyzer like Cppcheck - it can point you to possible UB reasons, like using uninitialized variables, ignoring function return codes etc. – Alex F Jul 02 '14 at 13:59
  • @mark that’s the first thing i did, everything looks fine – bolov Jul 02 '14 at 13:59
  • @EricFinn with debugging information /Z7 and Program Database /Zi symbols are **not** loaded. Program Database for Edit And Continue (/ZI) it is incompatible with /O2. and the fault presents only with /O2 – bolov Jul 02 '14 at 14:04

0 Answers0