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
Related
I'm trying to use JNI in C++ to call a method from Java.
I have tried this on a console application and it worked, but when I switch to a DLL that is loaded in any application, it fails with error "ERROR_ALREADY_EXISTS"
HMODULE jvmDLL = LoadLibrary("C:\\Program Files\\Java\\jre1.8.0_191\\bin\\server\\jvm.dll");
if (!jvmDLL) {
int error = GetLastError(); // this returns 183
}
This works perfectly fine on anything but a DLL injected into any application. It shouldn't be null.
Try this instead:
HMODULE jvmDLL = LoadLibrary("C:\\Program Files\\Java\\jre1.8.0_191\\bin\\server\\jvm.dll");
if (!jvmDLL)
jvmDLL = GetModuleHandle("jvm.dll");
}
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.
My goal is to build a Game Boy emulator. In order to do this, I would like to embed an SDL2 surface into a wxWidgets window.
I found this tutorial: http://code.technoplaza.net/wx-sdl/part1/, but my program crashes as soon as I run it. However I suspect this was intended for SDL1.2. Part of the program is shown below.
It seems that if I call SDL_Init() and also attempt to show a wxFrame (which, in this case, is MainWindow), it shows the window for a second and then the program crashes. I commented all other calls to SDL in my program so far, so it seems the problem lies with calling Show() on a wxFrame and initing SDL2 in the same program.
So the question is: can SDL2 and wxWidgets 3 work together? If not, could you guys suggest to me good alternatives a GUI of a Game Boy emulator? Does wxWidgets have its own graphics frame like Qt does (I'd rather avoid Qt)?
Thanks very much!
#include "MainApp.h"
#include "MainWindow.h"
#include <stdexcept>
namespace GBEmu {
static void initSDL() {
//This and SDL_Quit() are the only calls to the SDL library in my code
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
throw std::runtime_error("Fatal Error: Could not init SDL");
}
}
bool MainApp::OnInit()
{
try {
//If I comment out this line, the MainWindow wxFrame shows up fine.
//If I leave both uncommented, the window shows up quickly and then
//crashes.
initSDL();
//If I comment out this line and leave initSDL() uncommented,
//the program will not crash, but just run forever.
(new MainWindow("GBEmu", {50,50}, {640,480}))->Show();
} catch(std::exception &e) {
wxLogMessage(_("Fatal Error: " + std::string(e.what())));
}
return true;
}
int MainApp::OnExit() {
SDL_Quit();
return wxApp::OnExit();
}
}
wxIMPLEMENT_APP(GBEmu::MainApp);
EDIT: Here is more information on how it crashes: It crashes with a Segfault in what seems to be the pthread_mutex_lock disassembly file. This is the output in the console with stack trace:
Starting /home/dan/Documents/devStuff/GBEmuWx-build/GBEmuWx...
The program has unexpectedly finished.
/home/dan/Documents/devStuff/GBEmuWx-build/GBEmuWx crashed
Stack trace:
Error: signal 11:
/home/dan/Documents/devStuff/GBEmuWx-build/GBEmuWx(_ZN5GBEmu7handlerEi+0x1c)[0x414805]
/lib/x86_64-linux-gnu/libc.so.6(+0x36ff0)[0x7fb88e136ff0]
/lib/x86_64-linux-gnu/libpthread.so.0(pthread_mutex_lock+0x30)[0x7fb88c12ffa0]
/usr/lib/x86_64-linux-gnu/libX11.so.6(XrmQGetResource+0x3c)[0x7fb88d1ca15c]
/usr/lib/x86_64-linux-gnu/libX11.so.6(XGetDefault+0xc2)[0x7fb88d1a7a92]
/usr/lib/x86_64-linux-gnu/libcairo.so.2(+0x94dcf)[0x7fb88af8edcf]
/usr/lib/x86_64-linux-gnu/libcairo.so.2(+0x97110)[0x7fb88af91110]
/usr/lib/x86_64-linux-gnu/libcairo.so.2(cairo_surface_get_font_options+0x87)[0x7fb88af63e07]
/usr/lib/x86_64-linux-gnu/libcairo.so.2(+0x2b61f)[0x7fb88af2561f]
/usr/lib/x86_64-linux-gnu/libcairo.so.2(+0x2ef95)[0x7fb88af28f95]
This is a screenshot of where it seems to fail (line 7):
Update: In my MainWindow class, I attach a menu bar to the window. However, it seems when I comment out the setting of the menu bar, the window will show up fine even with initing of SDL. The menu bar will show up fine if I have initSDL() commented out but not the setting of the menu bar. Here is where I set the menu bar:
MainWindow::MainWindow(const wxString &title, const wxPoint &pos, const wxSize &size)
:wxFrame(nullptr, wxIDs::MainWindow, title, pos, size){
wxMenu *fileMenu = new wxMenu;
fileMenu->Append(wxID_EXIT);
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(fileMenu, "&File");
//commenting this line out will allow the window to showup
//and not crash the program
SetMenuBar(menuBar);
}
You are experiencing an old heisenbug.
The workaround is simple: you have to initialize SDL before wxWidgets (basically, before GTK). To achieve this, you have to change
wxIMPLEMENT_APP(GBEmu::MainApp);
to
wxIMPLEMENT_APP_NO_MAIN(GBEmu::MainApp);
so that wxWidgets doesn't hijack your main().
Then you have to create main() manually. In it, initialize SDL, then call wxEntry():
int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
std::cerr << "Could not initialize SDL.\n";
return 1;
}
return wxEntry(argc, argv);
}
More about the bug:
I have googled around a bit and found that this bug has come up in a few places over the years. There are open reports in many bug trackers that have stack traces very similar to the one you get here (with debug symbols).
The oldest report I could find is from 2005 (!!) from the cairo bug tracker (https://bugs.freedesktop.org/show_bug.cgi?id=4373).
My best guess is that the real hiding place of this bug in either in GTK, cairo, or X. Unfortunately I do not currently have the time to look into it more in depth.
I'm struggling with creating a window with the GLFW 3 function, glfwCreateWindow.
I have set an error callback function, that pretty much just prints out the error number and description, and according to that the GLFW library have not been initialized, even though the glfwInit function just returned success?
Here's an outtake from my code
// Error callback function prints out any errors from GFLW to the console
static void error_callback( int error, const char *description )
{
cout << error << '\t' << description << endl;
}
bool Base::Init()
{
// Set error callback
/*!
* According to the documentation this can be use before glfwInit,
* and removing won't change anything anyway
*/
glfwSetErrorCallback( error_callback );
// Initialize GLFW
/*!
* This return succesfull, but...
*/
if( !glfwInit() )
{
cout << "INITIALIZER: Failed to initialize GLFW!" << endl;
return false;
}
else
{
cout << "INITIALIZER: GLFW Initialized successfully!" << endl;
}
// Create window
/*!
* When this is called, or any other glfw functions, I get a
* "65537 The GLFW library is not initialized" in the console, through
* the error_callback function
*/
window = glfwCreateWindow( 800,
600,
"GLFW Window",
NULL,
NULL );
if( !window )
{
cout << "INITIALIZER: Failed to create window!" << endl;
glfwTerminate();
return false;
}
// Set window to current context
glfwMakeContextCurrent( window );
...
return true;
}
And here's what's printed out in the console
INITIALIZER: GLFW Initialized succesfully!
65537 The GLFW library is not initialized
INITIALIZER: Failed to create window!
I think I'm getting the error because of the setup isn't entirely correct, but I've done the best I can with what I could find around the place
I downloaded the windows 32 from glfw.org and stuck the 2 includes files from it into minGW/include/GLFW, the 2 .a files (from the lib-mingw folder) into minGW/lib and the dll, also from the lib-mingw folder, into Windows/System32
In code::blocks I have, from build options -> linker settings, linked the 2 .a files from the download. I believe I need to link more things, but I can figure out what, or where I should get those things from.
I tried reinstalling codeblocks and mingw, which solved the issue.
Seems like GLFW3 doesn't like having previous versions installed at the same time for some reason, so if anyone else is having a similar problem, you might want to try that.
I experienced similar problems in Cocos 3.8.1 and 3.10.
I have never installed codeblocks or mingw, so it did not make sense to install them for me.
The GLFW.lib file in the cocos directory is out of date.
http://www.glfw.org/download.html, and replace the lib file in your project with the latest one, and it may resolve your error.
I've been following this tutorial, and I've got to the point where we are instructed how to load and use bitmaps. Here is the current code:
#include "SDL/SDL.h"
#include <stdlib.h>
int main (int arg, char *argc[]) {
SDL_Surface* screen = NULL;
SDL_Surface* hello = NULL;
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode (256, 256, 32, SDL_SWSURFACE);
hello = SDL_LoadBMP("hello world.png"); // Here
if (hello == NULL) exit(0);
SDL_BlitSurface(hello, NULL, screen, NULL);
SDL_Flip(screen);
SDL_Delay(2000);
SDL_FreeSurface(hello);
SDL_Quit();
return 0;
}
hello, however, never gets any value other than NULL. I'm using Code::Blocks, and even if I scatter hello world.png through all possible directories of the project (be it inside bin, obj, either of the Debug's, the directory with the .cbp) or specify the whole path to the image in-code (as in SDL_LoadBMP("C:\Dir\hello world.png")) hello will get NULL.
What am I doing wrong?
OS is Windows
EDIT: Alright, apparently SDL_LoadBMP can only load .bmp files! How silly of me.
Edit: I mixed SDL_LoadBMP with IMG_Load, here's my new answer:
You can use SDL Image (include SDL_Image.h, link SDL_image.lib and make sure that the correct DLL for you file type is with your binary, if you need one) to call IMG_Load. IMG_Load will take care to resolve your file type and use the appropriate loaded to create a new SDL Surface. Remember to Free your surface when you're done with it.
Yes, it only loads bitmaps. You can use SDL_Image to load other types such as a png.