tag:blogger.com,1999:blog-12483086.post7143757791191962636..comments2022-12-20T16:07:19.919-05:00Comments on Dereferencing NULL: Mac OS X Debugging AdventuresDavid Ludwighttp://www.blogger.com/profile/02105674885904892236noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-12483086.post-61635169088712869382011-06-26T10:00:57.664-04:002011-06-26T10:00:57.664-04:00Thanks for this post! It helped me a ton!!!
-ATLA...Thanks for this post! It helped me a ton!!!<br /><br />-ATLAS PhysicistAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12483086.post-57948793185092763782009-06-24T17:18:53.407-04:002009-06-24T17:18:53.407-04:00Hi Daniel,
thanks for your answer!
The unique subc...Hi Daniel,<br />thanks for your answer!<br />The unique subclass is really a problem because I can only compile one template.<br /><br />But I found another workaround: I can replace the class name in the binary file using a hex editor. I just have to run a search and replace with the original class name and a new string with the same length.<br /><br />Perhaps I can write a little app that does this job …Unknownhttps://www.blogger.com/profile/11618444016717217486noreply@blogger.comtag:blogger.com,1999:blog-12483086.post-59865202310004677382009-06-22T15:52:04.153-04:002009-06-22T15:52:04.153-04:00Some code has to be unique for each screensaver, s...Some code has to be unique for each screensaver, so far that I can tell. Each screensaver needs at least one unique subclass of ScreenSaverView. If you're looking to create a lot of screensavers, my guess is that you'll need to create subclasses for each of them, however I could be wrong.<br /><br />Beyond creating unique subclasses for each screensaver, I created a shared library (aka, a .dylib file, creatable using XCode's provided templates) and put my code in there. Then I had my subclass of ScreenSaverView open the .dylib file via dlopen(), ask it for pointers to a few of its functions, then I called the functions as needed.<br /><br />Anyways, the general concept behind dlopen and dlsym is that you can open a shared library given its file name. For example:<br /><br />void * lib_handle = dlopen("path/to/my_shared_library.dylib", RTLD_LOCAL);<br /><br />Once you've opened a shared library, you can retrieve pointers to C functions within that library, which can be called like any other C function. For example:<br /><br />typedef (*my_function)(const char *, float);<br />my_function f = (my_function) dlsym(lib_handle, "my_function");<br />int x = f("blah blah", 123.45f);<br /><br />When you're done with the library, to note, be sure to close the handle via dlclose. For example:<br /><br />dlclose(lib_handle);<br />lib_handle = NULL;<br /><br /><br />I ended up wrapping my existing screensaver code in a C++ class, which I placed in the shared library, along with C functions that could instantiate and delete instances of the class. The class had member functions that could draw the scene (relevant as I was using OpenGL directly), tick the simulation, retrieve config values, set config values, etc.<br /><br />One note on dlopen/dlsym/dlclose, if you've never worked with those before, be careful of where and when you allocate and free memory. Typically, memory allocated within a particular shared library can only be deleted within that same shared library. Likewise, memory allocated within a particular application, or screen saver, can only be deleted within that app. Allocating memory in one library or app and then deleting it in another is a no no.David Ludwighttps://www.blogger.com/profile/02105674885904892236noreply@blogger.comtag:blogger.com,1999:blog-12483086.post-45263805287494212802009-06-22T14:53:01.170-04:002009-06-22T14:53:01.170-04:00Hi,
I think I have the same problem.
I've kin...Hi,<br />I think I have the same problem.<br /><br />I've kind of a screensaver template for flash content. The name of the main class is always the same so I can't install several of those screensavers at the same time.<br /><br /><br />You wrote:<br />"the one I chose to work with, is to load almost everything in a second dynamically loaded module, which gets loaded in such a way as not to cause naming clashes (via dlopen with RTLD_LOCAL.)"<br /><br />Can you give me example how to do this?<br />Would be great.<br />Thanks, FlorianUnknownhttps://www.blogger.com/profile/11618444016717217486noreply@blogger.com