ofxTouch compiling issue

Hello community!

I succeeded in compilng the HelloWorld example of ofxTouch and added some drawing functions to it and it was working perfectly fine.

However after a while, I started getting a compiling issue with this code.
It doesn’t give me any error, but it doesn’t go through although xcode says “succeeded!”

And in the debugger, it points to a line (ofxTouchApp.h:110):

  
filter->allocate( cwidth, cheight );  

Could anyone tell me what is wrong here? I’m stuck because it was working fine a few hours ago…

Thanks a lot! :o

Weird. Can you reproduce the error when you set everything up from scratch?

Yeah I downloaded the example zip again from your Touchkit website and downloaded new OF FAT package (with ofxTouch addon added) and test it, and it was still giving me the error. (it doesn’t say its an error though) However pngBrush example works fine in the same setup… and there is only an error in that allocate line.

Umm I will simplify and work off pngBrush example for now. I will update if there is any luck with HelloWorld example compiling…

I have the same problem (helloWorld crashes, brushes work) By adding

  
vidGrabber = NULL;  
		vidPlayer = NULL;  
		filter = NULL;   

to the ofxTouchApp constructor in ofxTouchApp.h it worked. So could someone tell me, why the pointers get automatically (and correct) nullified in one example and not nullified in the other? Or is this just randomness?

Hi,

So could someone tell me, why the pointers get automatically (and correct) nullified in one example and not nullified in the other? Or is this just randomness?

You’ll get undefined behaviour with uninitialized POD class-members. (bools, ints, floats, pointer,etc) This is c+±standard.

Only static variables get nullified by the compiler, not local variables or class members.

Some compiler do init class-members to 0, but only for debug builds. Visual Studio initializes class-members to a special bit-pattern to recognize uninitialized variables / class members, but also only for debug builds.

So do initialize EVERY class-member in the constructor, or you’ll have a hard time debugging nasty bugs / crashes.

cheers,
Stephan

Hi Stephan!
Thanks for pointing this out!

But still: When compiling BOTH applications in DEBUG mode, one crashes and the other does not. If this is random, well then I guess I miss random. (sounds like “To understand recursion you have to understand recursion” :? )

But I think thats exactly what you meant with

… or you’ll have a hard time debugging nasty bugs / crashes.

By the way, it has definitely to do with the pointers: when doing something like

  
  
//vidGrabber = NULL;  
vidPlayer = NULL;  
filter = NULL;  

ofVideoGrabber throws an error when trying to grab a frame, as it is not initialized correctly!

Regards,
Gestalt

‘uninitialized’ means ‘uninitialized’: whatever was at that physical memory location before is still there. for example if you were just watching a movie, it could be fragments of movie frame… so sometimes it will crash, and sometimes it will seem to work fine, but the subtle thing is that when it’s seeming to work fine it’s actually possibly writing random garbage over some important part of your program, which for example might make it crash in totally weird ways about 30 seconds later.

ok I see, this bug should have been fixed in v004 of ofxTouch. Anyways posted the fix to:
http://touchkit.nortd.com/download.html

Thanks for the feedback,

Is the new fix posted as a replacement of old “ofxTouch-Examples-001-xcode.zip”?
I downloaded the zip again and HelloWorld still didn’t compile it fine…umm. I didn’t change the code at all either. (with Latest OF FAT)

  
filter->allocate( cwidth, cheight );  

Akiko

(must have missed this post)

anyways, the fix is to ofxTouch not the example projects. This means you will have to update the ofxTouch code.