lilive
August 20, 2020, 2:32pm
#1
Hello,
How can we include glm::vec2
to use it in a class ?
I have:
DeformationMesh.h
#pragma once
include "glm/vec2.hpp"
class DeformationMesh
{
public:
void setOffset( int col, int row, glm::vec2 offset ) ;
} ;
DeformationMesh.cpp
#include "DeformationMesh.h"
void DeformationMesh::setOffset( int col, int row, glm::vec2 offset )
{ }
ofApp.cpp
#include "ofApp.h"
#include "DeformationMesh.h"
void ofApp::setup()
{
DeformationMesh deformation ;
deformation.setOffset( 0, 0, glm::vec2() ) ;
}
The app compiles but crash:
Exception code=0xc0000005 flags=0x0 at 0x0109660C. Access violation - attempting to read data at address 0xFFFFFFFF
If I replace #include "glm/vec2.hpp"
by #include "ofPoint.h"
in DeformationMesh.h, the app compiles and works.
#include <glm/glm.hpp>
, as adviced here , compiles and crashs.
Is it possible to use glm without importing the ofPoint ?
Thank you.
OF 0.11.0 / mingw32 / qtcreator
Not sure but as far as i can remember glm::vec2()
doesnt work anymore since the last glm update. You need to give it a initial value. It works when you include ofPoint.h
because i guess in there a special glm macro is defined which makes it so you dont have to give an initial values to glm objects.
Like i said, not sure and i cant test right now, but try glm::vec2(1.0)
instead of glm::vec2()
lilive
August 20, 2020, 4:23pm
#3
Thank you Marco. I tried:
deformation.setOffset( 0, 0, glm::vec2(0.0) ) ;
and
deformation.setOffset( 0, 0, glm::vec2(0.0,0.0) ) ;
but the app still crashes.
Can you try this?
#define GLM_FORCE_CTOR_INIT
#include <glm/glm.hpp>
instead of
include "glm/vec2.hpp"
theo
August 20, 2020, 5:29pm
#5
Yes @marco_v 's last reply is probably what is needed.
The safer thing to do would be to just include ofConstants.h
or ofMain.h
as any defines or glm includes that are needed will be set there.
lilive
August 20, 2020, 5:49pm
#6
#define GLM_FORCE_CTOR_INIT
#include <glm/glm.hpp>
works ! Thank you !
[edit]
#define GLM_FORCE_CTOR_INIT
#include "glm/vec2.hpp"
also works.
[/edit]
lilive
August 20, 2020, 5:52pm
#7
Hi Theo,
The safer thing to do would be to just include ofConstants.h
or ofMain.h
as any defines or glm includes that are needed will be set there.
I’m not 100% sure of this strategy, but I always try to use the minimal set of includes in my classes, to reduce the compile time.