Visual Studio 2012 GLFW 3.x Error Message - visual-studio

Long Story short, OpenGL beginner/dabbler, Using GLFW for self study purpose.
I downloaded GLFW precompiled binaries from here
and I followed this tutorial (I know its for VS2010 specific but still)
I have read numerous questions on linker errors for VS2012 + GLFW 3.x set up.
None of them solved my problem.
Here is what I have in my code so far.
#define GLFW_DLL
#include <glfw3.h>
#pragma comment(lib,"glfw3.lib")
#pragma comment(lib,"glfw3dll.lib")
#pragma comment(lib,"opengl32.lib")
int main(int argc,char** argv)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
Here is what I have in my
VC include directory.
VC lib directory
VC linker input options
System32 DLL
Compilation is successful. However, I get
Why, what is wrong with this set up?
UPDATE::
I tried placing all the files (dlls, lib and headers) in the project folder, still no results,
I still get the same error message.

The easiest solution would be to use the static library rather than the dll, thus removing the need for the dll.
To do this you need to remove the define for GLFW_DLL so you file reads:
#include <glfw3.h>
main() // code follows
And you need to remove the glfw3dll.lib from the additional dependencies but leave glfw3.lib and opengl32.lib.

Related

GTK+3 Application crashes in Debug mode, but runs fine in Release mode?

I am developing a GTK+3 application in C using MSVC (Visual Studio) on windows for a college project.
I've run the debugger and found that the application crashes while returning from a libffi call. The stack is corrupted and hence the program's return address is garbage.
The thing is, it runs fine in Release mode, probably due to optimization, but crashes in Debug mode. What could be the cause?
I have no clue how to resolve the problem... Any help would be appreciated.
Here is the part of the code which causes the error:
ffi_call_win64 (stack, frame, closure);
} // Error here
Exception thrown: read access violation.
pn was 0xFFFFFFFFFFFFFFFB.
MCVE
#include <gtk/gtk.h>
static void on_activate(GtkApplication* app) {
// Create a new window
GtkWidget* window = gtk_application_window_new(app);
// Create a new button
GtkWidget* button = gtk_button_new_with_label("Hello, World!");
// When the button is clicked, destroy the window passed as an argument
g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy), window);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show_all(window);
}
int main(int argc, char* argv[]) {
// Create a new application
GtkApplication* app = gtk_application_new("com.example.GtkApplication",
G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL);
return g_application_run(G_APPLICATION(app), argc, argv);
}

global try and catch block in qt

I am using Qt 4.8. Is there any way to have a global try and catch block for whole project. Example, if my application has two .cpp files. Is it possible way to catch exception across both .cpp files?
First of all, be warned that Qt doesn't play nice with exceptions. It was designed back in those days when exceptions were rather obscure feature of C++ so the use of exceptions was not generally considered a good practice for a whole bunch of implementation-related reasons.
Also be warned that as of Qt 5.7 the exception safety is not feature complete as the official doc currently tells:
Preliminary warning: Exception safety is not feature complete! Common cases should work, but classes might still leak or even crash.
If you use signal-slot connections within your classes, it's best to handle exceptions inside the slots which may throw them. As of Qt 5.7 not doing so is considered undefined behaviour.
If you just want to do some cleanup and/or error logging on any occasionally uncaught exception, you can either wrap the entire main() contents into try/catch block as the previous answer suggests or alternatively you can wrap the Qt's main event loop into such a block:
QApplication app(argc, argv);
...
try {
app.exec();
}
catch (const std::exception &) {
// clean up here, e.g. save the session
// and close all config files.
return 0; // exit the application
}
You can put in brackets the entire contents of your main() function as follows::
int main(int argc, char *argv[])
{
int ret = 0;
try
{
QApplication a(argc, argv);
QWidget w;
w.show();
ret = a.exec();
}
catch(...)
{
/* ... */
}
return ret;
}
See also: std::set_terminate()

Adobe AIR: Error #3500

EDIT: I was finally able to make a "Hello, World!" project set. If you are also having Error #3500 problems, see my answer below for a working project set.
I'm currently making a "Hello, World!" Native Extension for Adobe AIR with FlashDevelop. My Native Extension is thus meant to be used by Windows-x86 platforms, which I'm programming on.
I've built the ANE via a (custom) batch file. The test AIR Application which uses that ANE compiles fine, but, like so many other people I've seen the posts of, I'm getting Error #3500: The extension context does not have a method with the name helloWorld.
I've been trying to understand what was going on for three days now, and, despite fixing several causes, I'm still getting the same error.
It seems the application runtime never actually gets to call the initializeExtension function, since DebugView doesn't trace anything, even though my initializer uses OutputDebugString(L"Extension initialized");.
I feel a bit bad for posting a lot of code, but after three days and dozens of webpages read, I'm just not sure where my problem is coming from.
Anyway, application building is done in 3 steps :
1) Building the DLL in Visual Studio with the Release flag. I'm posting that code as a response to Michael's comment below, however, I'm not sure the error is coming from there.
My native side is mainly made up of a header and a C++ file :
// -------------------------
// | NativeExtensionTest.h |
// -------------------------
#pragma once
#include "FlashRuntimeExtensions.h"
#ifdef __cplusplus
EXTERN_C
{
#endif
__declspec(dllexport) void initializeExtension(
void** dataToSet,
FREContextInitializer* contextInitializer,
FREContextFinalizer* contextFinalizer
);
__declspec(dllexport) void finalizeExtension(
void* extData
);
__declspec(dllexport) void initializeContext(
void* contextData,
const uint8_t* contextType,
FREContext context,
uint32_t* nFunctionsToSet,
const FRENamedFunction** functionsToSet
);
__declspec(dllexport) void finalizeContext(
FREContext context
);
__declspec(dllexport) FREObject helloWorld(
FREContext context,
void* functionData,
uint32_t argc,
FREObject argv[]
);
#ifdef __cplusplus
}
#endif
And here is the implementation of the functions:
// ------------------
// | HelloWorld.cpp |
// ------------------
#pragma once
#include "stdafx.h" // precompiled header ; includes cstdlib, cstring and windows.h
#include "FlashRuntimeExtensions.h"
#include "NativeExtensionTest.h"
using namespace std;
void initializeExtension(
void** dataToSet,
FREContextInitializer* contextInitializer,
FREContextFinalizer* contextFinalizer
)
{
dataToSet = NULL;
*contextInitializer = &initializeContext;
*contextFinalizer = &finalizeExtension;
}
void finalizeExtension(
void* extData
)
{ }
void initializeContext(
void* contextData,
const uint8_t* contextType,
FREContext context,
uint32_t* nFunctionsToSet,
const FRENamedFunction** functionsToSet
)
{
*nFunctionsToSet = 1;
FRENamedFunction* functions = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)* (*nFunctionsToSet));
functions[0].name = (const uint8_t*)"helloWorld";
functions[0].function = &helloWorld;
functions[0].functionData = NULL;
*functionsToSet = functions;
}
void finalizeContext(
FREContext context
)
{ }
FREObject helloWorld(
FREContext context,
void* functionData,
uint32_t argc,
FREObject argv[]
)
{
char* hello = "Hello, World!";
unsigned int helloLength = strlen(hello) + 1;
FREObject ret;
FRENewObjectFromUTF8(helloLength, (const uint8_t*)hello, &ret);
return ret;
}
As alebianco requested, here is the build log when building the DLL. Note that I have an error at the very end of the log, at the end of the execution of a custom build batch file. I don't know where this error is coming from ; I didn't have that error last time I built that project. Besides, it's probably internal to FlashDevelop.
2) Building the ANE. I'm using a batch file to run the following commands:
To build the SWC, I invoke compc. After variable expansion, it looks like this:
compc -include-sources"C:\Users\Anthony Dentinger\Desktop\Native Extension Test\src" -output "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\NativeExtHelloWorld.swc" -load-config "C:\Users\Anthony Dentinger\AppData\Local\FlashDevelop\Apps\flexsdk\4.6.0\frameworks\air-config.xml" -swf-version 14
My src folder contains a simple class:
package
{
import flash.events.EventDispatcher;
import flash.external.ExtensionContext;
public class NativeExtHelloWorld extends EventDispatcher {
private var extContext:ExtensionContext;
public function NativeExtHelloWorld()
{
extContext = ExtensionContext.createExtensionContext("NativeExtHelloWorld", "helloWorldContext");
}
public function helloWorld() : String
{
return String(extContext.call("helloWorld"));
}
}
}
In turn, after copying both the DLL from my Visual Studio folder and library.swf (which I extract from the SWC) to ANE Build Files\platforms\Windows-x86, I build the ANE with adt. After variable expansion, the command looks like this:
call adt -package -target ane "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\HelloExtension.ane" "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\descriptor.xml" -swc "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\NativeExtHelloWorld.swc" -platform "Windows-x86" -C "C:\Users\Anthony Dentinger\Desktop\Native Extension Test\ANE Build Files\platforms\Windows-x86" .
Here is the extension descriptor that I provide adt:
<?xml version="1.0" encoding="utf-8"?>
<extension xmlns="http://ns.adobe.com/air/extension/3.1">
<id>NativeExtHelloWorld</id> <!--I'll later change that ID to something like com.example.myExt.HelloWorld-->
<name>Exension Name</name>
<description>Description of the Extension</description>
<versionNumber>0.0.1</versionNumber>
<copyright>© 2010, Examples, Inc. All rights reserved.</copyright>
<platforms>
<platform name="Windows-x86">
<applicationDeployment>
<nativeLibrary>HelloWorld.dll</nativeLibrary>
<initializer>initializeExtension</initializer>
<finalizer>finalizeExtension</finalizer>
</applicationDeployment>
</platform>
</platforms>
</extension>
3) Building the actual application. I'm using the default batch files made by FlashDevelop (with two modifications to include the ANE) for building AIR AS3 Projectors.
Note that, if I'm getting error #3500, it means (I suppose) that my application has successfully included my class from the ANE, since the constructor is working.
This is the application descriptor I'm using, in case that's helpful.
<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/15.0">
<id>TEST</id>
<versionNumber>1.0</versionNumber>
<filename>TEST</filename>
<name>TEST</name>
<initialWindow>
<title>TEST</title>
<content>TEST.swf</content>
<systemChrome>standard</systemChrome>
<transparent>false</transparent>
<visible>true</visible>
<minimizable>true</minimizable>
<maximizable>true</maximizable>
<resizable>true</resizable>
</initialWindow>
<supportedProfiles>extendedDesktop</supportedProfiles>
<extensions>
<extensionID>NativeExtHelloWorld</extensionID>
</extensions>
</application>
I'm using Flex (4.6.0) merged with the AIR SDK (22.0.0).
Have I done something wrong? What will help me fix this issue?
Once again, I'm sorry I posted quite a bit of code ; I've tried trimming down to what was most relevant.
Thanks in advance!
I've somehow solved the problem, and everything works now. I tried going back to see what I was doing wrong, but I can't quite figure it out. My guess is one of the batch files that copies and unzips the ANE was using the wrong target, so I ended up using the same old ANE, rather than using the ANE I was building (silly me).
Following Colonize.bat's request, here is a working Hello, World! example. I used VisualStudio 2013 and FlashDevelop to make this.
You can find several Error #3500 causes in the following files:
1_Build_DLL/Hello World/main.cpp
2_Build_ANE/lib/descriptor.xml
2_Build_ANE/src/HelloWorldExtension.as
Causes of some other errors I've read about (or encountered!) as also indicated in other files. In fact, the custom batch files indicate the procedure to follow in order to make and use your own ANE.
NOTE : Don't try to build directly from these files. I'm using batch files in order not to have to run commands and copy/paste/unzip files by hand, so the targets and environment variables will not be valid on your computer.

Efficiently write log file on Windows

I want to write log files. My application could be run on Linux and Windows. I've pretty much figured out how to do it for the former, thanks to this example:
void SyslogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
Q_UNUSED(context)
QByteArray localMsg = msg.toLocal8Bit();
switch (type)
{
case QtDebugMsg:
#ifdef __linux__
syslog(LOG_DEBUG, "Message (debug): %s", localMsg.constData());
#elif _WIN32
// WRITE INTO FILE
#else
#endif
break;
// etc.
}
}
int main()
{
// Install our message handler.
qInstallMessageHandler(SyslogMessageHandler);
// Send some messages, which should go to syslog.
qDebug("Debug log message from Qt test program");
}
source (2nd example)
However, I am wondering what would be the fastest way for Windows? Is using QFile or QTextStream an efficient way for writing this kind of information?
I was thinking about storing everything in a simple QString and then put everything in a file when the app closes or crashes (in the latter case, is that possible?).

how to fix unsatisfiedLinkError when generating dll for JNI in windows platform using g++

I'm new to native programming. I've been trying to fix the unsatisfiedLinkError past 8-9 hours but got no result. After a lot of googling and stackoverflowing, I got sick of fixing it, I'm posting my problem here. Somebody please please help me.
I'm using g++ compiler in windows 32bit environment.
Here are the files that I've created:
Demo.java
class Demo
{
// Declaration of the native method
public native int methodOfC(int arg1);
/*The native keyword tells the compiler that the implementation of this method is in a native language*/
/*Loading the library containing the implementation of the native method*/
static
{
System.out.println("Control is in Java.......going to call a C program......\n");
System.loadLibrary("try");
System.out.println("Congr8s no prob in CallApi.....\n");
}
public static void main(String[] args)
{
//invoking the native method
int sendToC,getFrmC;
if(args.length!=0) sendToC=Integer.parseInt(args[0]);
else sendToC=999;
Demo ob1=new Demo();
getFrmC=ob1.methodOfC(sendToC);
System.out.println("This is in Java......\n Got "+ getFrmC +" in return from C.");
}//end main
}//end Demo
Demo.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Demo */
#ifndef _Included_Demo
#define _Included_Demo
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Demo
* Method: methodOfC
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_Demo_methodOfC
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
DemoImp.c
#include <jni.h>
#include "Demo.h"
#include <stdio.h>
//definition of methodOfC()
JNIEXPORT int JNICALL Java_Demo_methodOfC(JNIEnv* exeenv, jobject javaobj, int getFrmJava)
{
printf("This is in the C program\n Got %d from java",getFrmJava);
printf("\n.......Exiting frm C\n");
return getFrmJava+1;
}
Here is how I compiled and run my prog.: screenshot here
C:\native>javac Demo.java
C:\native>javah -jni Demo
C:\native>g++ -c -l"C:\Java\jdk1.6.0_26\include" -l"C:\Java\jdk1.6.0_26\include\win32" DemoImp.c
C:\native>g++ -shared DemoImp.o -o try.dll
C:\native>java Demo 1234
Control is in Java.......going to call a C program......
Congr8s no prob in CallApi.....
Exception in thread "main" java.lang.UnsatisfiedLinkError: Demo.methodOfC(I)I
at Demo.methodOfC(Native Method)
at Demo.main(Demo.java:23)
C:\native>
I've already added "C:\native" in my system path variable.
I've uploaded all my files in mediafire. Here's the link native.zip
If possible please tell me how can I make 64bit version of dll. Thanks in advance.
You have missed out the package name in the DemoImp.c file.
The naming convention for C function is Java_{package_and_classname}_{function_name}(JNI arguments). The dot in package name shall be replaced by underscore.

Resources