SFML program crashes with non-ASCII character in window title - c++

So i just install SFML and was trying to do a simple programme, and the compilation works fine, but it's when I try to run the executable that it fails.
First I needed to do a trick to authorize the application to launch because it wasn't recognize by apple I follow those instruction to install SFML https://www.sfml-dev.org/tutorials/2.5/start-osx.php
After I managed to authorize the application when I run it I got this error message:
2020-11-24 10:20:55.638 exemple-graphisme1[2768:29657] *** Assertion failure in -[SFWindow setTitle:], NSWindow.m:2490
2020-11-24 10:20:55.640 exemple-graphisme1[2768:29657] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: aString != nil'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff204956af __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff201cd3c9 objc_exception_throw + 48
2 CoreFoundation 0x00007fff204be512 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff212776c9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 AppKit 0x00007fff22c7da75 -[NSWindow setTitle:] + 142
5 libsfml-window.2.5.dylib 0x000000010e5bf4fd _ZN2sf4priv15WindowImplCocoaC2ENS_9VideoModeERKNS_6StringEmRKNS_15ContextSettingsE + 269
6 libsfml-window.2.5.dylib 0x000000010e5b0e03 _ZN2sf4priv10WindowImpl6createENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE + 67
7 libsfml-window.2.5.dylib 0x000000010e5b02e5 _ZN2sf6Window6createENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE + 469
8 libsfml-graphics.2.5.dylib 0x000000010e61e823 _ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE + 99
9 exemple-graphisme1 0x000000010e582849 main + 233
10 libdyld.dylib 0x00007fff2033e631 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
[1] 2768 abort ./exemple-graphisme1
My code is very simple and only draw a point on the window
#include <SFML/Graphics.hpp>
using namespace sf;
using Point = Vector2f;
void draw_point(RenderWindow& w, Point pos, Color color) {
Vertex p[] = { Vertex(pos, color) };
w.draw(p, 1, sf::Points);
}
int main()
{
// ed: The line below originally contained "Hello World"
RenderWindow window(VideoMode(640, 480), "Ma super fenêtre");
window.clear(Color::White);
draw_point(window, {120, 5}, Color::Red);
window.display();
sleep(seconds(10));
return 0;
}
And I compiled my programme like this:
g++ -std=c++11 exemple-graphisme1.cpp -o exemple-graphisme1 -lsfml-system -lsfml-window -lsfml-graphics
Thanks for reading !

So the problem was very simple, I edited my code to translate it in english but in the beginning the first line was
RenderWindow window(VideoMode(640, 480), "Ma super fenêtre");
And the error occured because of the character 'ê'.
Thanks for your answer and sorry for this disappointing answer !

Related

QT Crash on exit with QtWebEngine

So I am using WebEngineView in my QML like this:
...
Loader {
// some properties
sourceComponent: WebEngineView {
...
}
}
In the c++ logic I am using QQuickWebEngineProfile::defaultProfile() in the constructor and destructor
MainViewModel(QObject* parent) : QObject(parent)
{
// using QQuickWebEngineProfile::defaultProfile();
// getting cookieStore of the profile and connect it to some slots
}
~MainViewModel()
{
// using QQuickWebEngineProfile::defaultProfile();
// getting cookieStore of the profile and disconnect it from MainViewModel
}
So it's working perfectly, but when I am trying to close my app (calling qApp->quit()), it crashes. If I remove WebEngineView from QML it works, if I remove using of defaultProfile() in c++ it works. But I need these things.
Dump:
1 _threadid ucrtbased 0x7ffb48687c75
2 _threadid ucrtbased 0x7ffb48687e13
3 abort ucrtbased 0x7ffb4869e01d
4 `anonymous namespace'::messageHandler application.cpp 46 0x7ff7c2d2b1bf
5 qt_message_print qlogging.cpp 1844 0x7ffb08317fdf
6 qt_message qlogging.cpp 379 0x7ffb08318657
7 QMessageLogger::fatal qlogging.cpp 890 0x7ffb08316612
8 qt_assert qglobal.cpp 3354 0x7ffb08307a48
9 QAccessible::registerAccessibleInterface qaccessible.cpp 747 0x7ffb01df22bd
10 QAccessible::uniqueId qaccessible.cpp 767 0x7ffb01df2247
11 QQuickWebEngineViewPrivate::widgetChanged qquickwebengineview.cpp 982 0x7ffb4b2b5bda
12 QQuickWebEngineViewPrivate::bindViewAndWidget qquickwebengineview.cpp 972 0x7ffb4b2b5b6e
13 QQuickWebEngineViewPrivate::releaseProfile qquickwebengineview.cpp 200 0x7ffb4b2b2349
14 QtWebEngineCore::ProfileAdapter::~ProfileAdapter profile_adapter.cpp 127 0x7ffad4237f20
15 QtWebEngineCore::ProfileAdapter::`vector deleting destructor' Qt5WebEngineCored 0x7ffad4238678
16 std::default_delete<QtWebEngineCore::DevToolsFrontendQt::NetworkResourceLoader>::operator() memory 1758 0x7ffad41d9a75
17 std::unique_ptr<QtWebEngineCore::WebChannelIPCTransportHost,std::default_delete<QtWebEngineCore::WebChannelIPCTransportHost>>::reset memory 1910 0x7ffad4287857
18 QtWebEngineCore::WebEngineContext::destroy web_engine_context.cpp 339 0x7ffad4295a87
19 QtWebEngineCore::WebEngineContext::destroyContextPostRoutine web_engine_context.cpp 425 0x7ffad4295bf8
20 qt_call_post_routines qcoreapplication.cpp 336 0x7ffb087276ef
21 QApplication::~QApplication qapplication.cpp 714 0x7ffb07767046
...
30 main main.cpp 63 0x7ff7c21d4640
It tried to access main window which at that moment has already been deleted. To resolve this problem I had to delay destruction of my main window. I've done it with
QObject::deleteLater()

SDL_CreateWindowFrom() with Qt widget under Mac OS

I am using libSDL2 in a Qt app. The code is working well under Linux and Windows but is failing under Mac OS. Here is the crash output:
2015-05-12 10:24:35.598 testapp[4621:105425] -[QNSView title]: unrecognized selector sent to instance 0x7fdfbac7b8e0
2015-05-12 10:24:35.643 testapp[4621:105425] An uncaught exception was raised
2015-05-12 10:24:35.643 testapp[4621:105425] -[QNSView title]: unrecognized selector sent to instance 0x7fdfbac7b8e0
2015-05-12 10:24:35.643 testapp[4621:105425] (
0 CoreFoundation 0x00007fff9332764c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff967686de objc_exception_throw + 43
2 CoreFoundation 0x00007fff9332a6bd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff93271a84 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff932715f8 _CF_forwarding_prep_0 + 120
5 testapp 0x000000010446af59 Cocoa_CreateWindowFrom + 73
6 testapp 0x000000010445fe1d SDL_CreateWindowFrom_REAL + 205
7 testapp 0x000000010417c83c main + 380
8 testapp 0x000000010417c6b4 start + 52
9 ??? 0x0000000000000001 0x0 + 1
)
That sample code reproduce the crash. Again it is working under Linux and Windows but not under Mac OS.
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
if (SDL_VideoInit(NULL) != 0) {
qCritical("SDL_VideoInit() error: %s", SDL_GetError());
return EXIT_FAILURE;
}
QWidget* qwidget = new QWidget();
SDL_Window* sdlWindow = SDL_CreateWindowFrom((void*) qwidget->winId());
if (sdlWindow == NULL) {
qCritical("SDL_CreateWindowFrom error: %s", SDL_GetError());
return EXIT_FAILURE;
}
return app.exec();
}

Q_ASSERT - "Incorrect format specifier"

I have a Q_ASSERT():
Q_ASSERT(QString("%1").arg(0) != "0");
When it fails, it shows an Abort/Retry/Ignore message box, but in the text it says:
File: f:\dd\vctools\crt_bld\self_x86\crt\src\output.c
Line: 1120
Expression: ("Incorrect format specifier", 0)
With this call stack:
0 _output_s_l output.c 1120 0x5dbee38d
1 _vsnprintf_helper vsprintf.c 140 0x5dbb00e8
2 _vsnprintf_s_l vsprintf.c 288 0x5dbb0610
3 _vsnprintf_s vsprintf.c 340 0x5dbb0880
4 _VCrtDbgReportA dbgrptt.c 301 0x5dc2571e
5 _CrtDbgReportV dbgrpt.c 241 0x5dc24992
6 _CrtDbgReport dbgrpt.c 258 0x5dc2494b
7 qt_message_output qglobal.cpp 2232 0x5d43bacf
8 qt_message qglobal.cpp 2298 0x5d43bc69
9 qFatal qglobal.cpp 2481 0x5d43c059
10 qt_assert qglobal.cpp 1999 0x5d43b629
But if I change it to:
Q_ASSERT(QString("0").arg(0) != "0");
It works as expected, showing
File: global\qglobal.cpp
Line: 2232
ASSERT: "QString("0").arg(0) != "0"" in file ..\MyProject\tester.cpp, line 132
So why this strange behavior, is it a bug in Qt?
Turned out to be a bug in Qt, in qt_message_output they have this line:
int ret = _CrtDbgReport(_CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, buf);
Should have been
int ret = _CrtDbgReport(_CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, "%s", buf);
They are passing the entire line contained in Q_ASSERT() as a format specifier.

lldb assertion failure when attempting to print vector

I get the error
lldb: /home/hannes/.llvm/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2271: uint64_t ::RecordLayoutBuilder::updateExternalFieldOffset(const clang::FieldDecl *, uint64_t): Assertion `ExternalFieldOffsets.find(Field) != ExternalFieldOffsets.end() && "Field does not have an external offset"' failed.
Aborted (core dumped)
when I try to print a vector<string>. Does anyone know why this happens, and how to fix it? The equivalent works just fine in gdb (there are a number of reason why I'd rather use / have to use lldb over gdb).
I'm running Ubuntu 12.10 with llvm, clang and lldb trunk.
The program, build instructions and lldb command sequence:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using std::for_each;
using std::begin;
using std::end;
int main() {
std::vector<std::string> vec{"Hello","World","!"};
for_each(begin(vec),end(vec),[](const std::string& s) {
std::cout << s << " ";
});
std::cout << std::endl;
return 0;
}
clang++ -g -c -std=c++11 main.cpp
clang++ -std=c++11 main.o -o test
lldb test
Current executable set to 'test' (x86_64).
(lldb) break -n main
invalid command 'breakpoint -n'
(lldb) breat set -n main
error: 'breat' is not a valid command.
(lldb) break set -n main
Breakpoint 1: where = test`main + 26 at main.cpp:5, address = 0x0000000000400aea
(lldb) run
Process 24489 launched: '/home/hannes/Documents/Programming/CXX/test/test' (x86_64)
Process 24489 stopped
* thread #1: tid = 0x5fa9, 0x0000000000400aea test`main + 26 at main.cpp:5, stop reason = breakpoint 1.1
frame #0: 0x0000000000400aea test`main + 26 at main.cpp:5
2 #include <string>
3
4 int main() {
-> 5 std::vector<std::string> vec{"Hello","World","!"};
6 return 0;
7 }
n
Process 24489 stopped
* thread #1: tid = 0x5fa9, 0x0000000000400c72 test`main + 418 at main.cpp:6, stop reason = step over
frame #0: 0x0000000000400c72 test`main + 418 at main.cpp:6
3
4 int main() {
5 std::vector<std::string> vec{"Hello","World","!"};
-> 6 return 0;
7 }
frame variable
lldb: /home/hannes/.llvm/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2271: uint64_t <anonymous namespace>::RecordLayoutBuilder::updateExternalFieldOffset(const clang::FieldDecl *, uint64_t): Assertion `ExternalFieldOffsets.find(Field) != ExternalFieldOffsets.end() && "Field does not have an external offset"' failed.
Aborted (core dumped)
Log output with debug level 10:
Logging from function (<frame object at 0x3172f20>, '/usr/lib/python2.7/dist-packages/lldb/formatters/cpp/gnu_libstdcpp.py', 141, '__init__', ['\t\tlogger = lldb.formatters.Logger.Logger()\n'], 0)
Providing synthetic children for a map named vec
Logging from function (<frame object at 0x3170d10>, '/usr/lib/python2.7/dist-packages/lldb/formatters/cpp/gnu_libstdcpp.py', 214, 'update', ['\t\tlogger = lldb.formatters.Logger.Logger()\n'], 0)
Does the same thing happen if you say frame variable --raw?
This command is meant to dump your vector disabling data formatters. In the specific case you will get (assuming no crashes) the in-memory layout of the vector instead of the printout of the strings you stored there.
I am mostly trying to figure out if the data formatters are or not a part in this issue.

SDL Video Init causes Exception on Mac OS X 10.8

I have just ported my C++ game to OS X and the first time it ran I get the following exception when trying to call SDL_SetVideoMode.
2012-09-28 15:01:05.437 SCRAsteroids[28595:707] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 259'
* First throw call stack:
(
0 CoreFoundation 0x00007fff8b53b716 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff90e30470 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8b53b4ec +[NSException raise:format:] + 204
3 AppKit 0x00007fff8a26a579 _NSCreateWindowWithOpaqueShape2 + 655
4 AppKit 0x00007fff8a268d70 -[NSWindow _commonAwake] + 2002
5 AppKit 0x00007fff8a2277e2 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 1763
6 AppKit 0x00007fff8a22692f -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1568
7 AppKit 0x00007fff8a2262ff -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
8 libSDL-1.2.0.dylib 0x0000000107c228f6 -[SDL_QuartzWindow initWithContentRect:styleMask:backing:defer:] + 294
9 libSDL-1.2.0.dylib 0x0000000107c20505 QZ_SetVideoMode + 2837
10 libSDL-1.2.0.dylib 0x0000000107c17af5 SDL_SetVideoMode + 917
11 SCRAsteroids 0x0000000107be60fb _ZN11SDLGraphics4initEP6IWorldii + 291
)
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
My init code looks like this:
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
return false;
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (!videoInfo) {
fprintf(stderr, "Video query failed: %s\n",
SDL_GetError());
return false;
}
/* the flags to pass to SDL_SetVideoMode */
videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */
/* This checks to see if surfaces can be stored in memory */
if (videoInfo->hw_available)
videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;
if (w == 0) {
widthViewport = videoInfo->current_w;
heightViewport = videoInfo->current_h;
cout << "Will use full screen resolution of ";
videoFlags |= SDL_FULLSCREEN;
} else {
cout << "Will use full user supplied resolution of ";
widthViewport = w;
heightViewport = h;
videoFlags |= SDL_RESIZABLE; /* Enable window resizing */
}
cout << widthViewport << "x" << heightViewport << "\n";
/* This checks if hardware blits can be done */
if (videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
/* Sets up OpenGL double buffering */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
/* get a SDL surface */
surface = SDL_SetVideoMode(widthViewport, heightViewport,
SCREEN_BPP, videoFlags);
It gets into that last SDL call and throws the exception above. I have tried it in both full screen and resizable window mode, same thing.
I build my app old school, on the command line, as opposed to using Xcode.
SDL_main was yet again the culprit. My C++ main routine was in a file that does not include SDL.h, so it was not being redefined to SDL_main. The code that includes SDL is instead in a reusable static library, no main routine you see. I manually changed the name of my function to SDL_main and this means that SDL provides the essential main routine. I don't like doing this, but for the moment, on SDL 1.2.15 for Mac, it is necessary.
On Windows, the same new code causes linker conflicts. That's a new problem.
There are problems with calling the videocard in cocoa. So you need to initalize it before calling SDL_Setvideomode
Add the following method, and call it first in your main method
#include <dlfcn.h> //To make it work on mac
//This must be called before playing with SDL, else it won't work on osx.
void pre_init()
{
void* cocoa_lib;
cocoa_lib = dlopen( "/System/Library/Frameworks/Cocoa.framework/Cocoa", RTLD_LAZY );
void (*nsappload)(void);
nsappload = (void(*)()) dlsym( cocoa_lib, "NSApplicationLoad");
nsappload();
}
`
Same issue, but solved by linking libSDLmain (as well as libSDL). This in turn requires two frameworks: Foundation and Cocoa.
I didn't rename the main function.