IRC Log Viewer » #firebreath » 2011-07-15

IRC Nick Time (GMT-7) Message
dougma 01:07 hi all, i'm new to osx development. :) Would you say it's safe for my plugin to schedule a NSURLConnection on the mainRunLoop?
linearray 02:07 taxilian_away: I'm curious, do you develop firebreath with xcode or VS?
someone-noone 02:07 Hello!
FireBreathBot 02:07 someone-noone: 14 Jul 14:04Z <neilg_> tell someone-noone No, there's no limitation on using the Mac audio subsystem from a plugin. Plus I also use SDL_mixer in my plugin!
someone-noone: 14 Jul 14:05Z <neilg_> tell someone-noone My guess is you're loading SDL_mixer dynamically (which is normal) and it's not loading the .dylib from the correct location. It's probably trying to load it from the browser's location! You need to give the .dylib a good install name. Use install_name_tool!
someone-noone 02:07 .tell
tell nelig_ Actually, i'm not using SDL_mixer, instead i'm playing audio with SDL_OpenAudio and a callback which is sending decoded PCM16 data to it. The problem is in this callback. In a desktop application SDL_Audio receives data, but in the plugin - not. Currently, i'm searchin why it's happening.
can i use tell command?
linearray 03:07 yes
someone-noone 03:07 what did i do wrong?
linearray 03:07 but you need to talk to the bot
someone-noone 03:07 through /w ?
linearray 03:07 FireBreathBot: tell someone-noone hi!
FireBreathBot 03:07 linearray: I'll pass that on when someone-noone is around.
someone-noone 03:07 FireBreathBot: tell nelig_ Actually, i'm not using SDL_mixer, instead i'm playing audio with SDL_OpenAudio and a callback which is sending decoded PCM16 data to it. The problem is in this callback. In a desktop application SDL_Audio receives data, but in the plugin - not. Currently, i'm searchin why it's happening.
FireBreathBot 03:07 someone-noone: I'll pass that on when nelig_ is around.
someone-noone: 09:02Z <linearray> tell someone-noone hi!
someone-noone 03:07 thx
I have some SDL events which must to be handled in the main thread of application(due to mac limitations). I found ScheduleOnMainThread function which is scheduling my function call 1 time. Is there any similar function that i can call my function each time when it goes through the loop?
or how can i do it manually
someone-noone 03:07 Another question: my libav* libraries that are linked to the plugin project are writing some useful for me stuff to the stderr. Afaik, it's impossible to read stderr from browser, so i've tried to remap stderr to a file(FILE *f = fopen(); stderr = f;). Again, on a desktop application remapping works, but in the plugin project - not. Is it possible to remap stderr?
someone-noone 06:07 Trying to get plugin's height and width by calling this->GetWindow()->getWindowHeight() from my plugin class and getting crash. What am i doing wrong?
linearray 06:07 I would attach the debugger and find out
someone-noone 06:07 i'm getting such error from debugger: Error from debugger: Previous frame inner to this frame (gdb could not unwind past this frame)
what does it mean?
linearray 06:07 sounds weird
google says this can happen if you mix llvm and gcc code
someone-noone 06:07 will try to clean and buil
build *
i thought that getting h\w is dissallowed in that way and even thought that it is a compiler problem
someone-noone 07:07 omg
seems i need to rebuild all my libraries on gcc
it is so..... weird
linearray 07:07 you had problems with llvm/gcc IIRC
so you switched to gcc-only?
someone-noone 07:07 there was a problem in compiling asm on x86_64 on gcc, and the same problem for i386 on llvm.
so i've mixed them: i386+gcc and x86_64+llvm into fat binary
now i'm going to kill myself
linearray 07:07 :)
someone-noone 07:07 i don't understand why i'm getting this error even if i switch to release mode and use "Run" instead of Debug
linearray 07:07 well
it does make sense, sort of
someone-noone 07:07 you know what
i rebuilt my libs on gcc only
linearray 07:07 does it work now?
someone-noone 07:07 and even tried different version of gcc(4.0) in xcode
and it doesn't work
linearray 07:07 ouch
someone-noone 07:07 switched to the snapshot without this error and going to rewrite new code in some other way.... may be it would help
so i've made some tests and now i'm sure that this bug is appearing when i try to call this->GetWindow()->getWindowHeight()
so it seems that getWindowHeight() was compiled under llvm
but i'm making clean all... so i don't understand how can it be
linearray 07:07 or maybe you hit some other issue and it doesn't have to do with llvm/gcc
someone-noone 07:07 what do you mean?
linearray 07:07 I mean, I don't know what's going on
someone-noone 07:07 very very strange...
am i right in this suggestion: when i'm making "Clean" all sources of firebreath are cleaning too
linearray 07:07 I usually just delete the build/ directory
someone-noone 08:07 and after that you are running ./
and just build
am i right?
linearray 08:07 yes
someone-noone 08:07 hm
i did it
i686-apple-darwin10-g++-4.2.1: /firebreath-dev/build/PluginCore/Debug/libPluginCore.a: No such file or directory
but wtf it should be built right now ?!
linearray 08:07 did you mess with cmake files?
in a bad way? :)
someone-noone 08:07 i didn't touch them
linearray 08:07 then I don't know
someone-noone 08:07 probably i know what is going on
sure, i was using wrong xcodeproject file
linearray 08:07 :)
someone-noone 08:07 and cleaning doesn't clean fb sources
Ed____ 08:07 Has anyone tried to use dynamic libraries in their plugin on Mac?
someone-noone 08:07 yes
predicting your question: use install_name_tool :)
neilg_ 08:07 Hey
Ed____ 08:07 ayup
install_name_tool? Is that a macro somewhere?
someone-noone 08:07 hello
what do you mean?
neilg_ 08:07 It's a built-in terminal command on Mac OS X
Ed____ 08:07 ah ok.
sry. not a Mac native..
neilg_ 08:07 That's fine, this time last year I was just starting to code on the Mac. I know how it feels. ;)
Ed____ 08:07 :D
I got my plugin all up and running under windows with my Dlls added to the msi..
all nice
just need to do the same with mac now..
neilg_ 08:07 someone-noone: There is no sandboxing that would stop the sound working from within a plugin. What's the difference between your test that works and the plugin that doesn't?
Awesome, good work!
Ed____ 08:07 should I use dynamic libs, or mush it all using static libs?
neilg_ 08:07 Okay, so on the Mac it has a weird thing with .dylib files
If you CAN use static libs then I'd recommend it
Ed____ 08:07 ah ok
someone-noone 08:07 But remember about LGPL license
neilg_ 08:07 I can't so I had to deal with the problematic way that .dylib files work
Ed____ 08:07 be great if you have info on that..
neilg_ 08:07 If you're using LGPL then you have two options: Use .dylib files or also release the .o files for your executable
Ed____ 08:07 dylib
linearray 08:07 the .o files? :)
Ed____ 08:07 we dont have any lgpl outselves, so it is down to firebreath/boost?
neilg_ 08:07 Yup, the object files that get linked to create your own library or executable
But in terms of .dylib files - the way they're weird compared to Windows is that when you build them you have to tell them where they're going to be stored
Xcode normally defaults to /usr/local/lib
linearray 08:07 unless I understand LGPL completely wrong you need to release source files for that
Ed____ 08:07 could be, in which case, we err on the side of caution and go with dynamic linking
someone-noone 08:07 nelig_: i've found the problem. It was my inattention. There was a constant that was corresponding to the speed of video playing. It was set to 0. And should be set to 1. So every time SDL called my callback it didn't received any data to play due to auido syncronization fail. Now i've fixed it and all is going fine
neilg_ 08:07 But if you want to package them inside your plugin bundle then you can use install_name_tool to change the install name (the location it was built with)
someone-noone: Awesome, glad to hear it! :D
Ed____ 08:07 ok, and then I need to sotre them in the bundle?
someone-noone 08:07 So, i've rebuild Firebreath with gcc4.2 and still getting this crazy debug error during runtime
neilg_ 08:07 There are some "magic" symbols that you can use with dylibs. But I recommend that you only use the one: @loader_path
What @loader_path does is to tell anything that links against it to use its own path to look for the .dylib
someone-noone 08:07 So the problem (i think) is in the getWindow()->getWindowHeigth
Ed____ 08:07 ah ok. So put that instruction somwhere in each dylib..
neilg_ 08:07 So let's say your plugin library inside the plugin bundle is stored in example.plugin/Contents/MacOS
You could tell your .dylib to be @loader_path/example.dylib
And when you link against it, the plugin will look for your .dylib in example.plugin/Contents/MacOS
Ed____ 08:07 ah ok
neilg_ 08:07 You can also use installl_name_tool to be something like @loader_path/../Resources/example.dylib
someone-noone 08:07 remember that fact that dylib could links against other libraries
neilg_ 08:07 And then linking against that would look in @example.plugin/Resources for example.dylib
That's right
someone-noone 08:07 so you should do the same recursively for each dylib
Ed____ 08:07 yes. I would add that to all our libs
anything else is a framework..
(standard Mac framework that is)
someone-noone 08:07 framework is easier to use
if you have framework i'd recommend to use it
neilg_ 08:07 So, you can see what your .dylib is doing with "otool -L"
Ed____ 08:07 we dont. code is all C/C++ but might make use of some Mac frameworks
Ok, and how to I get my dylib into the bundle?
someone-noone 08:07 just copy there
or you can make a script
that will make it automatically each time you need it
neilg_ 08:07 Exactly
Ed____ 08:07 Id want it to be part of the cmake, otherwise it gets a bit painful..
So, does this help me with that?
neilg_ 08:07 It should! I haven't done it that way, I have a CMake script that does it for me
At the end of my Mac/projectDef.cmake in my plugin project I have the line:
But in terms of .dylib files - the way they're weird compared to
Now THAT is the line ;)
Ed____ 08:07 :D
neilg_ 08:07 And so I have a CMake script called copy_dylibs.cmake which it calls (also passing in the build config so that you can copy different files for Debug or Release builds)
Ed____ 08:07 ok, so that cmake file copies you various dylibs into the bundle as a post-build of the plugin.
neilg_ 08:07 And that script looks like this:
message(STATUS "Copy debug files")
file(GLOB boost_files "${BOOST_DIR}/libboost*.dylib")
set(debug_files "${SANDSTONE_DIR}/bin-debug/mydylib.dylib" ${boost_files})
file(COPY ${debug_files} DESTINATION "${BINARY_DIR}/${BUILD_CONFIG}/SandstonePocket.plugin/Contents/MacOS/")
elseif(${BUILD_CONFIG} STREQUAL "Release")
Ed____ 08:07 and presumably, I can run the instal_name_tool using @loader_path ..
neilg_ 08:07 You only need to do that when you build the .dylib
Ed____ 08:07 NIce one neil. this is good stuff
neilg_ 08:07 Do you build your .dylib using Xcode or using make/CMake?
Ed____ 08:07 I started with XCode, but if make is a better option, I am happy to do that instead..:D
neilg_ 08:07 No, Xcode is great - that way you don't even have to use install_name_tool
Ed____ 08:07 ah, ok..
I take it there in XCODE property for the target?
neilg_ 08:07 Well... you might for anything you built that was built using make (like most LGPL libraries)
I highly recommend downloading and using
It shows you the dependency tree so you can see why something won't load. Normally because it can't find a .dylib
Ed____ 08:07 yes, that will be handy. I am a GUI man.. :D
neilg_ 08:07 It's the Mac equivalent to Windows' Dependency Walker:
Ed____ 08:07 Yeh, and I find that very valuable
neilg_ 08:07 But anyway, in Xcode for your .dylib, go to your target, right click and select "Get Info"
Ed____ 08:07 like I saw, I am a complete newb to the shiny side
neilg_ 08:07 Click on the "Build" tab and in the search box at the top type in "install" to narrow down what you're looking for
Ed____ 08:07 yep
someone-noone 08:07 linearray: haha
neilg_ 08:07 Under "Deployment", you'll see "Installation Directory". Change that to be @loader_path and then your dylib should magically work
someone-noone 08:07 i found the problem
Ed____ 08:07 Installation Directory
neilg_ 08:07 That's it! You should be all set now. :)
Ed____ 08:07 Cool
there must be a way to set that from cmake too? do you reckon?
someone-noone 08:07 i was using getWindowHeight() in PluginReady, but should do it in onWindowAttached
neilg_ 08:07 someone-noone: That's right. That's caused me problems before too! :)
someone-noone 08:07 huh. it's good that it wasn't llvm problem
Ed____ 08:07 awsome sauce. I am going to hack about and cause some damage now.. Cheers Neil.
someone-noone 09:07 question related to objective-c. I've declared new variable in @implementation. How can i access it from object?
not in @implementaion, but in @interface
stuartmorgan 09:07 someone-noone: not to be flip but... if you are going to be writing Objective-C code, shouldn't you learn the basics of Objective C?
someone-noone 09:07 just need a quick answer, but thanks !
stuartmorgan 09:07 someone-noone: so you don't think you'll need to understand, say, the memory management model before you start adding variables to things?
someone-noone 09:07 i guess yes
i understand what are you wanting to tell me now
stuartmorgan 09:07 I ask because stackoverflow is filled with people who have clearly attempted to write code in ObjC without ever learning anything about it, just by copy and pasting random snippets and such
And they don't understand why their code leaks like a sieve, or crashes randomly, or doesn't work
Or, usually, all three
someone-noone 09:07 i have another objectives in my mission i can let myself to make stupid mistakes like memory leaks or so
also, unfortunately, i have no time learning objective-c. But one day i will do it, because it's intersting
also i have some experience writing application's on mac, but without obj-c. So i know something about crashes and etc.
but anyway i agreed with you that "normally" it should be done in the way you are talking
so i've just asked stupid question and wanted to receive stupid answer, that's all
neilg_ 09:07 I really advise reading through
It'll take you 15 minutes, will give you a crash course in how memory management works - and will answer your question
someone-noone 09:07 actually, i've solved my problem, but thanks! I guess i can read it for 15 mins
stuartmorgan 09:07 someone-noone: I'm having a hard time imagining a scenario where you need to write code in a language but it doesn't matter if the code actually works correctly
A leaky proof-of-concept may be fine, but without knowing how the language works having the proof of concept not crash, and do what you think it does, will be quite challenging
someone-noone 09:07 well, if i say you that i'm editing 100% working obj-c code and just need to save 1 pointer in that object without any changes at all
and if i say you that in future i will not use obj-c
stuartmorgan 09:07 someone-noone: and you don't care if this pointer stays valid?
You are saving it, but never need to read it later and have what you think was there actually be there?
someone-noone 09:07 i know lifetime of this object
i read it
someone-noone 09:07 taxilian: how can i access main thread?
taxilian 10:07 someone-noone: I'm going to second stuartmorgan's point here; you really shouldn't be trying to write Objective C if you don't know what you're doing, and it sounds like you really don't. There are a lot of significant dangers there
but in C++ you can generally call a method on the main thread using the CallOnMainThread or ScheduleOnMainThread functions on your browserhost object
someone-noone 10:07 what if i want to do it every time main thread enters a loop?
if i want to handle own events/
taxilian 10:07 you can't that way
what are you actually trying to do?
someone-noone 10:07 i have code, written in C. It is generating SDL events. They should be handled in main thread. How can i do it?
taxilian 10:07 what are SDL events?
what event mechanism do they use?
someone-noone 10:07 cocoa
actually you can handle it by yourself
in the example they are handling it in main () function in for (;;)
taxilian 10:07 give me a link to the example
someone-noone 10:07
taxilian 10:07 you can't put that on the main thread
you'll have to run it on a new thread and hope that's possible
someone-noone 10:07 why not?
taxilian 10:07 because you can't block on the main thread
someone-noone 10:07 that is causing obj-c memory leaks
taxilian 10:07 and SDL_WaitEvent is going to block until an event occurs
someone-noone 10:07 yeap... you're right... i forgot that it would block it
stuartmorgan 10:07 someone-noone: are you talking about console logging about autorelease pools?
someone-noone 10:07 yes
stuartmorgan 10:07 If so, you need to read about autorelease pools
someone-noone 10:07 oaky
stuartmorgan 10:07 It's a solvable problem
Although you'd also want to make sure that this library you are using is threadsafe
someone-noone 10:07 but i didn't use any obj-c code there
stuartmorgan 10:07 someone-noone: but apparently they do
And you need to understand the memory model of Cocoa, and autorelease pools, in order to fix it
If this stuff is for handling user events though, you have a bigger problem if this is for a plugin
because plugins don't get system input events, so an abstraction around them (if that's what this is) isn't going to work
taxilian 10:07 I'm kinda hoping that isn't what is happening; neilg_ may know, he says he's used SDL
someone-noone 10:07 actually, i can forget SDL_Event
i have own event loop that is handling events
but i'm getting autorelease errors that is stuartmorgan is talking
so i've started to read about memory management
stuartmorgan 10:07 How can you have an event loop in a plugin?
someone-noone 10:07 in a separate thread? why not?
stuartmorgan 10:07 For user input events?
someone-noone 10:07 if i handle only "user"'s event
if i understand right (for 5 mins of reading) i should create own pool there
taxilian 10:07 someone-noone: are you talking about an event loop that gets system events? a cocoa event loop? or are you talking about your own seperate event system that you created that only handles your own thing?
someone-noone 10:07 third
taxilian 10:07 okay, that should be doable, as long as it is on your own thread and all your stuff is threadsafe
someone-noone 10:07 yes. i have a queue of jobs that is locking when you try to push or do the job
stuartmorgan 10:07 someone-noone: you don't just need a pool, you need appropriately scoped pools. If you just slap one pool at the top level of the thread you'll effectively leak everything SDL ever autoreleases
someone-noone 10:07 unfortunately, i don't understand what are you talking about :)
taxilian 10:07 hmm. Google code has (finally) added git support; perhaps I'll set that up as a mirror for the github repo
stuartmorgan 10:07 someone-noone: it's almost as if you should learn about the language/framework you are trying to write code in, like we told you an hour ago you should and you said you didn't need to :P
See also
someone-noone 10:07 i understood my mistakes
actually leaking is in NSWindowGraphicsContext objects. So i guess it's when you use SDL_Surface* stuff. But i will not do it in a plugin, instead i will draw with OpenGL like in BasicMediaPlayer
so i guess there will be no need in "scoped pool"
but how i can check this errors in plugins? if i even couldn't remap stderr
taxilian 10:07 use logging
!wiki logging
FireBreathBot 10:07 8 results found. Note: Results limited to 8
"struct FB AsyncLogRequest Members":
"struct FB AsyncLogRequest":
"Live Chat":
someone-noone 10:07 what about system errors? Like autorelease pool error?
neilg_ 10:07 I'm definitely not using SDL events
I'm only using SDL_mixer for playing sounds
taxilian 10:07 someone-noone: check the system console
someone-noone 10:07 thx, now i see
_pq_ 10:07 hello
got a quick question: is that any guarantee on browser thread calling plugin api?
meaning, it's possible for different instances of plugin to be called from different threads?
taxilian 11:07 no, it is not
the plugin will always get called from the same thread
_pq_ 11:07 cool
that's true both for activex and npapi?
taxilian 11:07 yes
_pq_ 11:07 that's really helpful
taxilian 11:07 though for activex that thread will not actually be the "main thread" of the application, it will always be the same thread
_pq_ 11:07 i'm finally addressing the issue of multiple plugin instance
taxilian 11:07 and all calls back to the browser have to be made on that same thread, which is why we have CallOnMainThread and ScheduleOnMainThread; of course, JSObjects do that automatically
_pq_ 11:07 yep i guessed something like that
only doubt was if it was licit for browser to handle each plugin instance in a different thread
that would break a lot of my code
someone-noone 11:07 thanks for help guys(stuartmorgan,taxilian,linearray). Today you had provided me a lot of useful info.
Have a nice weekend!
taxilian 11:07 good luck
someone-noone 11:07 i hope i didn't annoy you still :P
_pq_ 11:07 nice weekend to everyone i'm leaving too
and thanks for prompt answer taxilian
taxilian 11:07 yw
mukki 12:07 hey guys
Sajty 12:07 hi taxilian
taxilian 12:07 hell
Sajty 12:07 I have made a pull request. If you have some time could you check it?
taxilian 12:07 git pull request
FireBreathBot 12:07 1 open pull request:
sajty: FIREBREATH-112: Add Keyboard support on linux.
Sajty 12:07 FireBreathBot is slow :P