After a recent software update to the phonon libraries, I've noticed that a media playing application that I wrote is no longer able to loop tracks. The code in question is below. The first track is set, and once it nears completion it is set to play again.
void Alarm::Start(bool useCustom)
{
if(useCustom)
{
media->setCurrentSource(Phonon::MediaSource(this->_CustPath));
this->_UsingCustomPath=true;
}else{
FileIO::ExtractAudio();
media->setCurrentSource(Phonon::MediaSource(this->_DefaultPath));
this->_UsingCustomPath=false;
}
media->play();
connect(media,SIGNAL(aboutToFinish()),this,SLOT(RepeatAllTheThings()));
this->_isPlaying=true;
}
void Alarm::RepeatAllTheThings()
{
if(this->_UsingCustomPath)
{
media->enqueue(this->_CustPath);
}else{
media->enqueue(this->_DefaultPath);
}
}
After running through the debugger a few times I noticed this message:
"Ignoring source as no aboutToFinish handling is in progress"
A quick google search doesn't tell much about this message. It looks like a check for a private variable (that I dont have access to) has been added (a diff of the file)
Does anyone know if I just discovered a new bug in phonon, or am I some how using the enqueue method incorrectly?
EDIT:
The code above only fails about 1/2 the time. Very confused. Currently running phonon-gstreamer 4.6.3
Solved with this work-around:
media->play();
connect(media,SIGNAL(finished()),this,SLOT(RepeatAllTheThings()));
void Alarm::RepeatAllTheThings()
{
if(this->_UsingCustomPath)
{
media->setCurrentSource(Phonon::MediaSource(this->_CustPath));
}else{
media->setCurrentSource(Phonon::MediaSource(this->_DefaultPath));
}
media->play();
}
Related
is it okay to do something like this, the code snippet is of course not complete, just to show what I mean:
void draw(IplImage* image){
cvLine(image,cvPoint(20,20),cvPoint(100,100),cvScalar(0,0,255),1);}
int main(){
cvNamedWindow("preview",CV_WINDOW_AUTOSIZE);
IplImage* image;
image=cvCreateImage(cvSize(480,360),8,3);
while(true){
draw(image);
cvShowImage("preview",image);
int ops=cvWaitKey(10)
if ops!=-1 break;}
cvReleaseImage(&image);cvDestroyWindow("preview");return 0;
}
or will it cause problems if I don't return the IplImage like this:
IplImage* draw(IplImage* image){
cvLine(image,cvPoint(20,20),cvPoint(100,100),cvScalar(0,0,255),1);return image;}
well, the reason why I'm asking is that sometimes it works if I don't return the IplImage. However it may also happen that I'll receive some sort of NULL pointer error message in other cases. If for example I release the image in the function and then create it anew right after that, still being in that function, a crash may happen.
You don't need to return anything, but you definitely need to check for failures!
The problem is that you are not coding safely. You are never checking for failures when calling OpenCV functions, which may result in draw() receiving a NULL pointer as parameter, and that might cause a crash or some other weird behavior along the way.
The first thing you should do is start coding defensively:
IplImage* image = cvCreateImage(cvSize(480,360),8,3);
if (!image)
{
// print error and quit
}
and it wouldn't hurt to add a safety check inside your function:
void draw(IplImage* image)
{
if (!image)
{
// print error
return;
}
cvLine(image,cvPoint(20,20),cvPoint(100,100),cvScalar(0,0,255),1);
}
While looking at source of Ayende's Racoon Blog, I saw this in global.asax.cs:
// Work around nasty .NET framework bug
try
{
new Uri("http://fail/first/time?only=%2bplus");
}
catch (Exception)
{
}
This appears to be a workaround for a bug that happens on the first request. Does anyone know what the bug is or how to reproduce it?
A bit of googling gets to this Ayende blog post from March 2010 from which I quote an excerpt:
I can reproduce this now, here it how it got there:
public class Strange : MarshalByRefObject
{
public void WTF()
{
Console.WriteLine(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
new Uri("http://localhost:58080/indexes/categoriesByName?query=CategoryName%3ABeverages&start=0&pageSize=25");
}
}
public class Program
{
private static void Main()
{
var instanceAndUnwrap = (Strange) AppDomain.CreateDomain("test", null, new AppDomainSetup
{
ConfigurationFile = ""
}).CreateInstanceAndUnwrap("ConsoleApplication5", "ConsoleApplication5.Strange");
instanceAndUnwrap.WTF();
}
}
That took some time to figure out.
From the comment thread below, which I have skimmed but not read in detail, the root cause appears to be an error in the machine root config file, which is only parsed once per ?AppDomain, hence the lack of an error the second and subsequent times.
Habitually using this construct having been burned by it once is the kind of habit that programmers accumulate through hard experience. The less experienced may snigger "cargo cult" or "programming by coincidence", to which the more experienced will just smile and nod.
Sorry for my english, but I have the next problem. I am writing a window manager using Qt 4.7 and Xlib. I have class Manager that inherits QApplication and reimplemented method X11EventFilter in it. In X11EventFilter method I catch necessary events from XServer. When I receive MapRequest event, I catch appearing of new window and reparent it to my own widget. And when I create that widget and call QWidget::show() or QWidget::winId() methods, program crashes. What is the problem?
Here is a method where widget is creating. I wonder, when this function calls few times on start of program, everything is OK.
void Manager::createClientWindow(Qt::HANDLE pWinID)
{
QMWindowWidget *lWindowWidget = new QMWindowWidget(pWinID);
/*some code*/
lWindowWidget->show();//crash is here
Qt::HANDLE widgetId = lWindowWidget->winId();//and here
/*some code*/
}
Here is a x11EventFilter method where createClientWindow function is called
bool Manager::x11EventFilter(XEvent *pEvent)
{
switch(pEvent.type)
{
/*some code*/
case MapRequest:
{
Qt::HANDLE lWindow = pEvent->xmaprequest.window;
QMWindowWidget* lWidget = findWidget(lWindow);
if (!lWidget)
{
lWidget = dynamic_cast<QMWindowWidget*>(QWidget::find(lWindow));
}
if (lWidget)
{
XMapWindow(QX11Info::display(), lWindow);
lWidget->show();
XRaiseWindow(QX11Info::display(), lWidget->winId());
return true;
}
else
{
createClientWindow(lWindow);//here is where function is called
return true;
}
}
break;
/*some code*/
} //switch
return false;
}
The problem most likely resides in the code represented by /*some code*/. Since it is not known what's there, it's very difficult to pinpoint the exact cause of the problem. If you cannot show all the code, you will have to track the problem down yourself.
You will need to build in debug mode and link with the debug version of Qt. Then when the crash happens, look at the exact line of Qt source and analyse the broken data structures with a debugger and try to figure out why they are broken. Maybe set a watchpoint on a problematic variable and find out what code writes an invalid value there.
In order to program in low level languages such as C and C++ one has to learn how to do this stuff.
Problem is resolved! I paste this two strings before QApplication::exec()
XClearWindow(QX11Info::display(), QX11Info::appRootWindow());
XSync(QX11Info::display(), false);
I want to declaratively turn on and off logger for my Flex application and it seems that my usual way of determining if it's debug mode or not works only sometimes. The code for it:
isDebugSWF = new Error().getStackTrace().search(/:[0-9]+]$/m) > -1;
Do you know a better way for it?
Edit:
I posted answer below.
The static property Capabilities.isDebugger in the flash.system.Capabilities class specifies if the Flash player installed is a debug version or not. It requires Flash Player 9 or AIR 1.0 as the minimum version.
Keep in mind though that debug Flash Player installers are publicly available, and that there is nothing stopping users from installing the debug version of Flash. If have something sensitive that you want to hide, using conditional compilation would be a better option.
The previous approach was based on great article . One of the comments suggested that in Release the stacktrace is null, so I modified it properly:
protected function configureLogger() : void
{
if(!isDebugPlayer()|| !isDebugBuild())
{
// stop logging
Logger.hide = true;
}
else
{
// resume logging
Logger.hide = false;
}
}
private function isDebugPlayer() : Boolean
{
return Capabilities.isDebugger;
}
/**
* Returns true if the swf is built in debug mode
**/
private function isDebugBuild() : Boolean
{
var stackTrace:String = new Error().getStackTrace();
if(stackTrace == null || stackTrace.length == 0)
{
//in Release the stackTrace is null
return false;
}
//The code searches for line numbers of errors in StackTrace result.
//Only StackTrace result of a debug SWF file contains line numbers.
return stackTrace.search(/:[0-9]+]$/m) > -1;
}
This way I can finally configure ThunderBoltAS3 logger depending on current build type.
Looks like you are looking for the same, as answered in another post. Look here: How can you tell programmatically if a Flex App is running in debug mode?
We are using conditional compilation at our project :
Adobe Documentation
I'm trying to get the IFrameCommTest example (from the Flex-IFrame site) to work in Flex 4, and, while the IFrame itself works, the communication does not. In particular, I need to get the included HTML page to call functions from the flex app (I already have a way to get the Flex app to talk to the HTML).
I've exported the project to facilitate your help.
The problem, I suspect, is that the "parent.FABridge" doesn't exist. My guess is that something in flex4 changed with regard to how things are located in the DOM.
(This post is related to the earlier post about FABridge.
I thought this would be a clearer example of the problem. )
Thanks,
Brian
I've solved this my own self :D
The difference over the mechanism above is in the getFlexApp() function, and it provides a way to, well, get the flex object. Once the objecty it gotten, I just call the EIButtonClicked() function, and pass a value to it.
function getFlexApp(appName) {
if (navigator.appName.indexOf ("Microsoft") !=-1) {
return window.top[appName];
} else {
return window.top.document[appName];
}
}
function callFlexFunction() {
var sTxt ;
sTxt = document.getElementById('txt1').value;
alert('HTML/Javascript wants to tell you about ' + sTxt);
getFlexApp('iframeCommTest').EIButtonClicked(sTxt) ;
}
Meanwhile, the flex side has an external interface callback established. You can see that the "EIButtonClicked" referenced in the JS above is matched by the label for the callback in the AS below.
/**
* When the button is clicked.
*/
public function onEIButtonClicked(data:String):void {
Alert.show("Flash wants to tell you about " + data);
}
protected function application1_creationCompleteHandler():void {
// TODO Auto-generated method stub
if (ExternalInterface.available) {
ExternalInterface.addCallback("EIButtonClicked", onEIButtonClicked);
}
}