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();
}
Related
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()
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 !
I'm trying to install OpenGL in CLion on MacOS. My program compiles but when I run it I get this crashreport:
Time Awake Since Boot: 6200 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [1694]
VM Regions Near 0:
-->
__TEXT 0000000109550000-000000010957c000 [ 176K] r-x/r-x SM=COW /Users/USER/Documents/*
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 ??? 000000000000000000 0 + 0
1 SandBoxGL 0x000000010955223a main + 362 (main.cpp:30)
2 libdyld.dylib 0x00007fff6765acc9 start + 1
Thread 1:
0 libsystem_pthread.dylib 0x00007fff6785ab68 start_wqthread + 0
Thread 2:
0 libsystem_pthread.dylib 0x00007fff6785ab68 start_wqthread + 0
Thread 3:
0 libsystem_pthread.dylib 0x00007fff6785ab68 start_wqthread + 0
Thread 4:
0 libsystem_pthread.dylib 0x00007fff6785ab68 start_wqthread + 0
Thread 5:
0 libsystem_pthread.dylib 0x00007fff6785ab68 start_wqthread + 0
Thread 6:
0 libsystem_pthread.dylib 0x00007fff6785ab68 start_wqthread + 0
Thread 7:
0 libsystem_pthread.dylib 0x00007fff6785ab68 start_wqthread + 0
Thread 8:
0 libsystem_pthread.dylib 0x00007fff6785ab68 start_wqthread + 0
Thread 9:: com.apple.NSEventThread
0 libsystem_kernel.dylib 0x00007fff6779be36 semaphore_wait_trap + 10
1 libdispatch.dylib 0x00007fff67601aed _dispatch_sema4_wait + 16
2 libdispatch.dylib 0x00007fff67601fbf _dispatch_semaphore_wait_slow + 98
3 com.apple.HIToolbox 0x00007fff2c35b940 _BeginEventReceiptOnThread + 159
4 com.apple.AppKit 0x00007fff2ab32555 _NSEventThread + 37
5 libsystem_pthread.dylib 0x00007fff6785f109 _pthread_start + 148
6 libsystem_pthread.dylib 0x00007fff6785ab8b thread_start + 15
Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x000000010957d350 rbx: 0x0000000000000000 rcx: 0x00007fbe2b8090ff rdx: 0x0000000000000002
rdi: 0x00007fbe2ae0eb40 rsi: 0x00007fbe2af78610 rbp: 0x00007ffee66af8f0 rsp: 0x00007ffee66af898
r8: 0x00007fff8e186e30 r9: 0x0000000000000010 r10: 0x00007ffee66afa38 r11: 0x0000000109600b46
r12: 0x0000000000000000 r13: 0x0000000000000000 r14: 0x0000000000000000 r15: 0x0000000000000000
rip: 0x0000000000000000 rfl: 0x0000000000010202 cr2: 0x0000000000000000
Logical CPU: 4
Error Code: 0x00000014 (no mapping for user instruction read)
Trap Number: 14
...(binary)
It is not the exact same code as on the glfw website, I had to import glad, added the macro on the third line and a couple of prints. The code on the website didn't even compile. That's the code:
#include <iostream>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <glad/glad.h>
int main(void)
{
if (!glfwInit()) {
return -1;
}
GLFWwindow* window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
std::cout << "window: " << window;
if (!window)
{
std::cout << "problems with window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
I installed the glfw library using HomeBrew and the glad library I downloaded on this website https://glad.dav1d.de with gl version 4.1 and all extensions. I added all of the zip folder in the libs/glad folder in my project and linked it in the CMakeLists.txt file. Thats the CMakeLists.txtfile:
cmake_minimum_required(VERSION 3.16)
project(SandBoxGL)
set(SRC_FILES
src/main.cpp
)
set(HEADER_FILES)
find_package(glfw3 REQUIRED)
find_package(OpenGl REQUIRED)
add_library(glad "libs/glad/src/glad.c")
include_directories("libs/glad/include")
set(LIBS glfw glad)
add_executable(SandBoxGL ${HEADER_FILES} ${SRC_FILES})
include_directories(
"${CMAKE_SOURCE_DIR}/src"
"${CMAKE_SOURCE_DIR}/include"
)
target_link_libraries(${PROJECT_NAME} ${LIBS})
When I run it in the debugger in CLion it stops at the glClear(GL_COLOR_BUFFER_BIT); function and gives me that error message EXC_BAD_ACCESS (code=1, address=0x0). When I remove that line I get a black window as expected. Has anyone an idea how I can fix that?
It is possible that GLAD is not starting up. Try adding something like this:
//Previous stuff
glfwMakeContextCurrent(window);
int gladErr = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); //Starts up GLAD
assert(gladErr != 0); //Checks glad is ok
if(GLAD_GL_VERSION_4_1){ //Makes sure OpenGL 4.1 is supported (not really necessary with window hints)
std::cout << "4.1 OK" << std::endl;
}
while (!glfwWindowShouldClose(window))
//Render loop
I was using custom c++ functions, and it includes c++ standard libraries.
While i using c++ standard libraries, error occured: make: *** [start] Segmentation fault: 11
The full error message is here:
./build/main;
Stack dump:
0. Program arguments: ./build/main
0 main 0x0000000107c3ab4c llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1 main 0x0000000107c3b109 PrintStackTraceSignalHandler(void*) + 25
2 main 0x0000000107c38b86 llvm::sys::RunSignalHandlers() + 118
3 main 0x0000000107c3eccc SignalHandler(int) + 252
4 libsystem_platform.dylib 0x00007fff6af3642d _sigtramp + 29
5 libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338721827824
6 libsystem_platform.dylib 0x0000000111a41213 _sigtramp + 18446603343312760323
7 libsystem_platform.dylib 0x0000000111a410d1 _sigtramp + 18446603343312760001
8 libsystem_platform.dylib 0x0000000111a4101a _sigtramp + 18446603343312759818
9 libsystem_platform.dylib 0x0000000111a40c2d _sigtramp + 18446603343312758813
10 libsystem_platform.dylib 0x0000000111a409ed _sigtramp + 18446603343312758237
11 libsystem_platform.dylib 0x0000000111a40147 _sigtramp + 18446603343312756023
12 libsystem_platform.dylib 0x0000000111a40032 _sigtramp + 18446603343312755746
13 main 0x0000000107a3b706 main + 1830
14 libdyld.dylib 0x00007fff6ad3d7fd start + 1
15 libdyld.dylib 0x0000000000000001 start + 18446603338723895301
make: *** [start] Segmentation fault: 11
I had create a demo project to show this error in minimum code: https://github.com/vifird/jit. And i had tested it in two new MacBooks(MacOSX 10.15), those both displayed this error, so i think it may not be a problem of libc++.
Here are my code files:
main.cpp
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/TargetSelect.h"
#include <fstream>
#include <iostream>
using namespace std;
using namespace llvm;
using namespace llvm::orc;
int main(int argc, char *argv[]) {
InitLLVM X(argc, argv);
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
ThreadSafeContext context(std::make_unique<LLVMContext>());
ExitOnError ExitOnErr;
auto JTMB = ExitOnErr(JITTargetMachineBuilder::detectHost());
JTMB.setCodeModel(CodeModel::Small);
auto jit =
ExitOnErr(LLJITBuilder()
.setJITTargetMachineBuilder(std::move(JTMB))
.create());
jit->getMainJITDylib().addGenerator(
ExitOnErr(orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(
jit->getDataLayout().getGlobalPrefix())));
char ffi_file[] = "build/ffi";
llvm::Error err =
jit->addObjectFile(ExitOnErr(errorOrToExpected(MemoryBuffer::getFileAsStream(ffi_file))));
if (err) {
cout << "error addObjectFile" << endl;
return 1;
};
char func_name[] = "add";
auto func_add = ExitOnErr(jit->lookup(func_name));
int (*func)(int, int) = (int (*)(int, int))func_add.getAddress();
int result = func(111, 222);
cout << "result: " << result << endl;
return 0;
}
ffi.cpp, which will build and output build/ffifile.
#include <vector>
extern "C" int add(int a, int b) {
std::vector<int> vc;
vc.push_back(1);
return a + b;
}
When vc.push_back(1); was included in ffi.cpp, error occoured, when delete this line , it runs ok.
Here is my environment
OS: MacOSX 10.15.2
LLVM: 10
Clang: 11
Here is my cmake file
cmake_minimum_required(VERSION 3.15.0)
project(jitdemo)
SET (CMAKE_C_COMPILER /usr/bin/clang)
SET (CMAKE_CXX_COMPILER /usr/bin/clang++)
SET ( CMAKE_BUILD_TYPE Debug )
find_package(LLVM REQUIRED CONFIG)
message(STATUS ">>Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS ">>Using LLVMConfig.cmake in: ${LLVM_DIR}")
add_compile_options(-std=c++17)
add_compile_options(-stdlib=libc++)
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR})
add_subdirectory(link)
llvm_map_components_to_libnames(llvm_libs support core orcjit irreader nativecodegen)
add_executable(main main.cpp)
target_link_libraries(main link ${llvm_libs})
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.