Application error despite console displaying no errors? - c++

I’ve been watching this tutorial and I’ve run into an error. For some reason even though I fixed the unresolved external symbols errors, the application error is still available. https://imgur.com/a/ppngHxL I don't know whether it's due to my computer because it says it's a 64 bit processing system, but nothing seems to work.
I tried using one tutorial in that I extract the sdl2.dll file then copy pasting it into the windows32 file, and that still didn't work, and the properties panels don't have a compatibility tab on my computer. I'm not sure what to try next. Here's the code
#include "SDL.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *window = SDL_CreateWindow("title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 400, SDL_WINDOW_SHOWN );
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
SDL_Delay(3000);
return 0;
}

The application does not start properly (0xc000007b)
The root cause is the lack of the required DLL, and the wrong version of the dll is also a possible reason, the report error of the two are exactly the same.
I noticed the following question. Is it possible that different versions caused your problem. But I tested and found nothing, it work.
Have you performed this step? Copy SDL2.dll to the root directory of your project. This may also cause some problems, although the compilation is successful.
Of course, it is more likely that you are missing other system files or dlls. It is not easy to guess which file missing. If this is the case, I am sorry that I have no better suggestions.

Related

SDL_Image loading a png returns nullptr

Alright so I'm trying to make a game engine for myself, and I've decided that it would be best to start loading images as files other than bitmaps using the SDL Image library. I've set up the library correctly according to conversations online, include set up and linker set up, and yet when I try to load a file that does indeed exist it just returns an empty surface.
Heres the code loading the file...
SDL_Surface* background = IMG_Load("Assets/bg.png");
background = SDL_ConvertSurface(background, mtrx->format, 0);
if (!background) {
ofstream file("text.txt");
file << IMG_GetError() << endl;
file.close();
}
...And the error I get in "text.txt"...
Parameter 'surface' is invalid
At the beginning of the script I have included SDL.h, then SDL_image.h, and the window initiation has IMG_Init(IMG_INIT_PNG) after SDL_Init. Visual studio shows no errors whatsoever, and everything BUT IMG_Load works fine.
All help would be appreciated, and I can provide any other code that might be helpful!

ISO-10646 XFont encoding issue

I'm trying to use ISO-10646 fixed font in my X Window program. It has to support English, Russian and Greek letters but it doesn't. In xfontsel window all is OK but in my program only English displays correctly. Using something like g++ -fexec-charset=ISO-10646 ... or g++ -finput-charset=ISO-10646 ... wasn't helpful. How can I fix it?
Test app window screenshot:
xfontsel window screenshot:
Test app code:
#include <X11/StringDefs.h>
#include <X11/Xaw/Command.h>
int main(int argc, char **argv) {
Widget widget = XtInitialize(argv[0], "simple", NULL, 0, &argc, argv);
XtVaCreateManagedWidget(
"English Русский ελληνικά", labelWidgetClass, widget,
XtNfont, XLoadQueryFont(XtDisplay(widget),
"-Misc-Fixed-Medium-R-Normal--20-200-75-75-C-100-ISO10646-1"
), XtNwidth, 500, XtNheight, 100, NULL
);
XtRealizeWidget(widget);
XtMainLoop();
}
Your program uses UTF-8-encoded single byte strings, which is not what Xt/Xaw expects. -fexec-charset won't help any.
With pure Xlib (no toolkit) you would use Xutf8DrawString and friends, but Xt and Xaw have no provision for that.
Xaw theoretically supports 2-byte encodings of labels with XtNencoding set to XawTextEncodingChar2b, but I could never make it work with UTF-16.
XChar2b lbl[] = { {0x04, 0x40}, {0x04, 0x43},
{0x04, 0x41}, {0x04, 0x41},
{0x04, 0x3a}, {0x04, 0x38},
{0x04, 0x39}, {0, 0}};
XtVaCreateManagedWidget(
"w00t", labelWidgetClass, widget,
XtNfont, XLoadQueryFont(XtDisplay(widget),
"-Misc-Fixed-Medium-R-Normal--20-200-75-75-C-100-ISO10646-1"
), XtNwidth, 500, XtNheight, 100,
XtNencoding, XawTextEncodingChar2b,
XtNlabel, lbl,
NULL
);
This particular string works. I hope you can figure out how to produce an arbitrary label. However, a null byte at either high or low position terminates the string, so no English text can be displayed with this method.
Perhaps a copy of Xaw on my machine is not up to date. There is a patch that should make it work here but I don't know if it's applied on this copy and cannot be bothered to build a patched version from sources. Perhaps you shouldn't rely on it if you want to distribute your code dynamically linked, as not every machine will have an up-to-date Xaw library. This patch was made in 2014.
My advice would be not to rely on i18n abilities of Xaw. Use raw X11 with Xutf8DrawString, or a modern toolkit such as Qt or Gtk or FLTK or wxWidgets, which should all work with UTF-8 seamlessly. As the last resort, subclass Xaw widgets as needed and make them work with Xutf8DrawString.
Update I have checked the source from a Gentoo ebuild which ought to be up to date. The patch is not applied there, there is strlen everywhere, XChar2b is not working. A typical Xaw code fragment:
len = strlen(label);
...
if (len) {
if (w->label.encoding)
XDrawString16(XtDisplay(gw), XtWindow(gw), gc,
w->label.label_x, y, (XChar2b *)label, len / 2);
else
XDrawString(XtDisplay(gw), XtWindow(gw), gc,
w->label.label_x, y, label, len);
}
Clearly this cannot possibly have any hope of working correctly.

Can any Windows terminal's color palettes be edited with pdcurses?

I'm a big fan of ASCII aesthetics, and the idea of creating graphics from a terminal appeals to me.
I'm playing around with pdcurses on a Windows environment, and I found a very interesting property: init_color. However, it does not seem to work at all! Not only is the color range of every terminal I've tried (CMD.exe, ConEmu and Console2) limited to 16 colors, I cannot seem to be able to edit the palette.
I couldn't find anything about this topic online.
So- Is it at all possible? And if not, are there alternatives? For example, I know ConEmu has palettes, but I do not know how to tell it what palette to use from a c++ program.
Here's a sample of code I tried:
#include <curses.h>
int main()
{
init_color(1, 700, 600, 111);
initscr();
noecho();
if(has_colors() == FALSE)
{
endwin();
printf("Your terminal doesn't support color..!\n");
return 1;
}
init_color(2, 555, 555, 222);
start_color();
init_pair(1, 1, 0);
init_pair(2, 2, 0);
attron(COLOR_PAIR(1));
printw("aaaa ");
attron(COLOR_PAIR(2));
init_color(12, 700, 600, 111);
printw("bbbb\n");
getch();
endwin();
return 0;
}
The code to do it in PDCurses 3.4 used to work in some versions of Windows, but later Windows (XP Service Pack 3+) broke it. However, it's been updated to work with current Windows if you grab the latest PDCurses code from git.
BTW, you should only call init_color() after initscr().

Debugging app with CImg library included

I'm writing program to analyze 3D raw images. I have strange problem with loading this files. During debugging:
(...)
string input_filename = file_i;
CImg<unsigned char> img_org(500, 500, 500, 1);
img_org.load_raw(file_i, 500, 500, 500, 1);
(...)
I have IO Exception, looks like:
What is more, after compile, program works ok. It's important for me to debug entire program, because I must look into further functions.
Ok, I've found out that debugger is looking for my .raw file in different folder. It was silly question, but already I have the answer.

SDL does not show its window if I use a logging library

I'm trying to use log4cplus in conjunction with SDL to make a little graphic application.
I'm using minGW and Eclipse CDT on windows.
My problem is that whenever I use the library, my SDL window is not shown.
Instead I get this on the console [New Thread 2624.0x1270] and that is it. No error message, no compilation/linking problem, nothing (see edit for precisions).
If I don't use the library, a similar message appears on the console and then disappears, and my SDL window is shown properly.
Below is an example of this behavior. If I comment the two lines starting with "Logger ", then everything is fine. If I do not, SDL window is not shown.
Edit: I've tried using just the logging library and commenting all the other code but this fails as well somehow. I cannot put a breakpoint on the logger code, eclipse tells me: Breakpoint attribute problem: installation failed and the code don't seem to be executed.
*Edit2:*I was on the wrong track, see my post below. Problem kind of solved.
Any Idea?
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_endian.h> /* Used for the endian-dependent 24 bpp mode */
#include "Screen.h"
#include <log4cplus/logger.h>
#include <iomanip>
using namespace log4cplus;
int main(int argc, char **argv) {
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Impossible d'initialiser SDL: %s\n", SDL_GetError());
exit(1);
}
SDL_Surface *screen;
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Impossible de passer en 640x480 en 16 bpp: %s\n", SDL_GetError());
exit(1);
}
Logger root = Logger::getRoot();
Logger log_1 = Logger::getInstance(LOG4CPLUS_TEXT("test.log_1"));
while(true)
{
SDL_Event event;
SDL_WaitEvent(&event);
switch (event.type) {
case SDL_KEYDOWN:
printf("La touche %s a été préssée!\n",
SDL_GetKeyName(event.key.keysym.sym));
//SDL_Quit();
break;
case SDL_QUIT:
exit(0);
}
Screen::DrawPixel(screen,20,20,200,10,10);
}
}
I have no experience with log4cplus, but I do know that you should be aware that SDL does some obnoxious rewiring of stdout and stderr.
I was going to say that you should move your Logger setup to after your SDL_Init call, but I just noticed that you don't even have one. Try calling SDL_Init before setting up your display.
I found the problem. I hadn't noticed the error gdb gave me when running the program: "
gdb: unknown target exception 0xc0000135". In fact the program didn't start at all.
This means it could not load a dll because of some path problems. I tried putting the dll I use for log4cplus in the system path, tried other workarounds like starting eclipse from but to no avail. One way I found to make it work is simply to put the dll in the Debug folder.
The problem with this gdb error is quite widespread (see google). This is not a proper fix, but I will live with it for the time being, so I consider the problem solved.