[Mono-dev] DirectFB and Mono
Csaba Balazs
csaba.balazs at researchstudio.at
Mon Jun 30 08:49:47 EDT 2008
Hello,
I minimized the C++ and C# codes. The C++ part inits the DirectFB.
Compiling / Running:
1. g++ -shared -D_REENTRANT -o libprobawrap.so probawrap.cpp
-I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/ -I/usr/include/directfb
-ldirectfb
2. gmcs Proba.cs
3. mono Proba.exe
The C# application inits first the DirectFB (with C++ library), and starts
making with Proba_Function garbage string and printing then to screen. .
If I use the DirectFBCreate command, the whole application fails and
exit, when
the mono GC starts, usually after 60-70 garbages.
Why can it happen? The sources are enclosed.
Thanks.
Csaba
Proba.cs:
---------------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
class Proba {
[DllImport("probawrap")]
private static extern void proba_init();
public Proba() {
proba_init();
}
private void Proba_Function() {
int i = 0;
while (true) {
string garbage = "garbage: " + i;
i++;
Console.WriteLine("C# Proba_Function - " + garbage);
}
}
public static void Main() {
Proba proba = new Proba();
proba.Proba_Function();
}
}
probawrap.cpp
---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <directfb/directfb.h>
#include <directfb/directfb_version.h>
/* macro for a safe call to DirectFB functions */
#define DFBCHECK(x...) \
{ \
err = x; \
if (err != DFB_OK) { \
fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
DirectFBErrorFatal( #x, err ); \
} \
}
IDirectFB *evas_gui_dfb;
extern "C" {
void proba_init() {
DFBResult err;
int argc = 2;
char* arg0 = "directfb";
char* arg1 = "--dfb:system=x11";
char** argv = new char*[2];
argv[0] = arg0;
argv[1] = arg1;
IDirectFB *evas_gui_dfb;
DFBCHECK( DirectFBInit(&argc, &argv) );
DFBCHECK( DirectFBCreate(&evas_gui_dfb) ); // <--- problem, if we use
delete argv;
}
}
---------------------------------------------------------------------------
Quoting Csaba Balazs <csaba.balazs at researchstudio.at>:
> Hello,
>
> I have found an interesting "bug". I wrote a simple C# sample, which
> calls a C
> function.
> This C function sets up the DirectFB (DirectFBInit and DirectFBCreate) and
> returns. And whenever the Garbage Collector starts running, it kills
> the whole
> application.
> I think they somehow interfere, and GC kills the directFB. Has anyone
> met this
> problem?
> What can be the solution?
>
> Thanks in advance:
>
> Csaba
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
More information about the Mono-devel-list
mailing list