How does a small change in code that never executes matter?

My problem is very strange , and since I cannot send the code, I will try to explain.

This is more like a philosophical problem - I hope someone has the time / knowledge to think about it.

1) I have project.cpp that looks exactly like this:

#include <pthread.h> #include <unistd.h> pthread_t pplayer_thread; void *play(void*); int main(int argc, char **argv) { pthread_create(&pplayer_thread, NULL, play_cb, NULL); usleep(5000000); return 0; } 

2) pplayer.cpp looks something like this:

 ... void *play_cb(void *arg) { // this starts movie using gstreamer and exits thread } ... 

3) not_executed _from_main.cpp looks something like this:

 ... extern MyClass *myObj; // this is included from .h file ... MyClass *myObj = NULL; ... some_function() { ... myObj = MyClass::createNew(args); ... } ... 

All this is due to various other libraries and tons of garbage, but this is mostly important.

-> Problem :

When I launched this, I should see a window playing the video clip using gstreamer for 5 seconds -> BUT, but I hear only the sound!

-> Strange thing :

When I comment out the line:

 myObj = MyClass::createNew(args); 

and run again -> I also see the gstreamer window (everything is ok)

-> Notes :

this may have something to do with:

  • the layout and character process of MyClass and its parent class (my best guess)
  • "static" keyword
  • "external" keyword
  • Mixing C and C ++

-> I ask again :

How does a small change in code that never executes matter?

(please, help)

+7
source share
4 answers

Sounds like you need to get familiar with chaos theory . In a fairly complex system, the smallest change can propagate through any instability inherent to them to the point that causes a significant difference.

In your case, it could be any of the implicit side effects of this method, so that the memory-related error becomes visible when the layout of the executable code changes.

You must use a debugger to track your code. Ensure that none of the allegedly executed code is actually executed. Your code may enter code codes that are mistakenly considered unavailable, or some other part of your program (such as a static initiator) may work.

Valgrind can also be useful if it is available for your platform - it will detect many memory errors, for example, I suspect that you have it in your hands. Unfortunately, this is not very good for detecting errors in the stack - your compiler can help there, however.

+7
source

This is most likely due to stackoverflow. You have something that does something bad by accessing things outside or other undefined behavior, and these are only triggers (or not) only in a specific configuration. Adding or removing a variable declaration may be like this.

+3
source

indicate that your sample code is not real code with the problem.

main is not the only entry point where the code can run, any global objects will execute their constructors, which can call all kinds of code. So maybe some of you are biting you.

Give it up or maybe put messages on the console to find out which paths are running.

+2
source

Is this your stream using myObj? If so, there may be a race condition between setting myObj to NULL and subsequent distribution.

0
source

All Articles