How to fix "assertion 'GDK_IS_SCREEN (screen)' failed" error in GTK+2 - gtk2

I'm trying to write a short C program, that makes all programs reload the GTK+2 theme, the way that LXAppearance does, when you click on apply.
Looking at LXAppearance's source code I found a function that does just that. The same function (without an if-else that only applies to LXSession) is also found in gtk-theme-switch.
This is the code written as a separate program:
#include <gtk/gtk.h>
int main()
{
GdkEventClient event;
event.type = GDK_CLIENT_EVENT;
event.send_event = TRUE;
event.window = NULL;
event.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
event.data_format = 8;
gdk_event_send_clientmessage_toall((GdkEvent*)&event);
}
When running the program I the following error:
(process:3428): Gdk-CRITICAL **: 21:38:49.599: IA__gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed
Segmentation fault (core dumped)
What am I doing wrong?

You've not initialized GTK. At the very least, to access your current X display with GTK, you need to call the gtk_init function before doing any other X-related things.

Related

Success compiling but no display, setting bkcolor

#include <graphics.h>
#include <conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TURBOC3\\");
setbkcolor(CYAN);
getch();
closegraph();
}
The compiling was successful and tried running it, but the result was I see no display for my code It's just a blink of screen and gone back to the console.
you need to point initgraph to bgi subfolder of turboc3
initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");
Yes your code may compile successfully but your code is having a runtime problem. Just add these line first below the line you initialized your graphics.
int errorcode = graphresult();
if (errorcode != grOk) { /* an error occurred */
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code(requires process.h) */
}
Through these lines runtime problems of graphics can be detected. Its just a safety method for avoid errors and system crash. Well these lines will tell you that they cannot find the file VGAEGA.bgi file. That's generally the default drivers of graphics.
The reason the file is not found is your path c:\\TURBOC3\\. see this post for avoiding the errors.

Access violation while initializing matlab-compiler dll / lib in c++ only during debugging

what I'm trying to do is integrate a MATLAB-Compiler dll/lib to an new c++ project.
I followed this instruction: How do I integrate my C++ shared Library generated from MATLAB which seams working good (no build errors and intelisense is working good, so it seams all required information are there).
I'm using a very simple mathlab code / function for testing:
function output = extest( arg1,arg2 )
output = arg1+arg2;
end
And the "default" c++ code for matlab functions:
#include "extest.h"
#include <cstdlib>
#include <stdio.h>
int main(int argc, char** argv){
mclmcrInitialize();
if (!mclInitializeApplication(NULL,0)){
std::cerr << "could not initialize the application properly" << std::endl;
return -1;
}
if(!extestInitialize()){
std::cerr << "could not initialize the library properly" << std::endl;
return -1;
}
else{
try{
//code itself (not jet reached therefore removed)
}catch(const mwException& e){
std::cerr << e.what() << std::endl;
return -2;
}
catch(...){
std::cerr << "Unexpected error thrown" << std::endl;
return -3;
}
extestTerminate();
}
mclTerminateApplication();
return 0;
}
After e few moments after the debugger tries to run the line if(!extestInitialize()) the following error gets thrown.
Exception thrown at 0x000002BF72E0EE55 in DllTestingCpp.exe: 0xC0000005: Access violation reading location 0x0000000000000008.
I can hit visual studios continue > button and it is continued after lets say 20x click on it. Starting the code by ctrl + F5 (without debugging) everything is working good.
Any ideas why this happens in debug mode? Or better how I can get rid of this error?
PS: extest is my lib name and using Matlab R2017a 64bit and Visual Studio 2017 (debugging with x64),
The same problem (Matlab2017 + VS 2015) for me.
Probably there is some conflict with java used by MATLAB.
I've fixed it by
const char *args[] = {"-nojvm"};
const int count = sizeof(args) / sizeof(args[0]);
mclInitializeApplication(args, count))
instead of
mclInitializeApplication(NULL,0)
I had the same issue(using VS2019) and I found the following answer here:
https://uk.mathworks.com/matlabcentral/answers/182851-how-do-i-integrate-my-c-shared-library-generated-from-matlab-r2013b-in-visual-studio-2013
I encountered this same issue and reported it to Mathworks. They responded that for VS2013 and later, the debugger is set to break when 0xc0000005 occurs, even though in this case it is handled by the JVM.
The fix is to go to Debug>Windows>Exception Settings>Win32 and uncheck '0xc0000005 Access Violation'. In VS2012, this setting is unchecked by default.
This seems to work o.k.

Cross-compile runtime error: Inconsistency detected by ld.so: dl-minimal.c: 136: realloc: Assertion `ptr == alloc_last_block' failed

I met a BAMR (Beyond All My Recognition) error, I have a small single-thread application, just create an openGL context and draw something for test purpose. It runs well both in Windows7 and Ubuntu64. These days I am porting it to Linux armv7 (arm-linux-gnuabihf), the host machine is ubuntu x64, gcc/g++ version is 4.6(arm-linux-gnuabihf), before this app I've been compiled several small apps and running well.
Every time I run this application will print below error:
/////////////////////
Step 1
Inconsistency detected by ld.so: dl-minimal.c: 136: realloc: Assertion `ptr == alloc_last_block' failed!
/////////////////////
Here is my code, it looks like each time the error happens before an if(..) clause? How strange it is! Anyone have any idea? Thanks a lot!
HRESULT TestWorkloadBase::CreateGLWindow()
{
printf("Step 1");
if (m_bPrompt) //m_bPrompt has been initialized
{
printf("Step 2");
int ProcessId = GetProcessID();
printf("Process Id is %d Starting... Please press a key to continue.\n", ProcessId);
printf("Step 3");
std::cin.ignore();
}
printf("Step 4");
#if !defined(_WIN32)
if (getenv("DISPLAY") == NULL)
{
setenv("DISPLAY", ":0.0", 0);
}
...
}
The "Step 1" will be printed each time.

Allegro 5 assertion fail

I am trying to load a bitmap with allegro 5.0.10
ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_set_path_filename(path, "Bitmap.bmp");
al_init_image_addon();
ALLEGRO_BITMAP *bmp = al_load_bitmap(al_path_cstr(path, '/'));
if (!bmp) {
fprintf(stderr, "No Background.bmp in this directory...");
return -2;
}
al_draw_bitmap(bmp, 0, 0, 0);
Once i tried to run the program in debug mode, i get this error:
Assertion failed!
Program: c:\allegro\bin\allegro-5.0.10-monolith-md-debug.dll
File: allegro-git\src\system.c
Line: 336
Expression: active_sysdrv
...
How do i fix this?
You need to initialize allegro by calling al_init(). Very few Allegro functions can be called before doing that.
#junyi00, you need to make sure that you call al_init() before trying to load any resources. In your code above, make sure al_init() is already called before calling al_get_standard_path(ALLEGRO_RESOURCES_PATH), al_set_path_filename(path, "Bitmap.bmp"), al_load_bitmap(al_path_cstr(path, '/')) and basically all the Allegro functions from there. No other Allegro functions can be called before this function except one or two. See http://manpages.ubuntu.com/manpages/artful/en/man3/al_init.3alleg5.html and http://manpages.ubuntu.com/manpages/zesty/en/man3/al_install_system.3alleg5.html These are links to the al_init() and al_install_system() Allegro function manual pages

Problem with LZO

So I am trying to use LZO in my application. Here is how I have included it:
#include "lzoconf.h"
#include "lzodefs.h"
#include "lzo1x.h"
/* portability layer */
static const char *progname = NULL;
#define WANT_LZO_MALLOC 1
#define WANT_XMALLOC 1
#include "portab.h"
Then in the application I do:
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return 4;
}
It compiles ok. No errors or warnings during compilation.
When I try to run my application though, there are two errors:
/home/richard/client/src/portab.h:145: undefined reference to `__lzo_align_gap'
Which points at this line in portab.h:
if (__lzo_align_gap(p, (lzo_uint) sizeof(lzo_align_t)) != 0)
{
printf("%s: C library problem: malloc() returned mis-aligned pointer!\n", progname);
exit(1);
}
return p;
And in my application:
/home/richard/client/src/main.cc:108: undefined reference to `__lzo_init_v2'
Which points to:
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return 4;
}
I have all the header files inside my source directory:
config.h
lzo1x.h
lzoconf.h
lzodefs.h
miniacc.h
portab.h
portab_a.h
What am I doing wrong?
I am compiling my application in Ubuntu 10.10 in Anjuta ide.
Headers is not enough, you need to link to the libraries. Have you read the documentation?