using transform
J43G3R

can someone point me to correct method of initialising transformations. I created a pointer to ALLEGRO_TRANSFORM and invoked al_identity_tranform on it.
"/build/allegro5-F6iykb/allegro5-5.2.6.0/src/transformations.c:147: al_identity_transform: Assertion `trans' failed.
Aborted (core dumped)"

This is the error

DanielH

You're passing a pointer? Does it actually point to an ALLEGRO_TRANSFORM?

Erin Maus

Generally you pass in a transform like this:

// This is allocated on the stack
ALLEGRO_TRANSFORM transform;

// Pass a pointer to a stack-allocated pointer
al_identity_transform(&transform);

Sounds like you might be doing something like this:

// This is a pointer to NULL
ALLEGRO_TRANSFORM* transform = NULL;
al_identity_transform(transform); // bad

Basically, al_identity_transform expects the memory for the transform you provide to be allocated. So it needs to pointer to an object on the stack (or in the heap, if the transform is a field in a class or struct).

bamccaig

A class or struct field is not implicitly on the heap at all. ::):-X Where it is allocated depends on how you define an instance of it. I know (hope) Erin knows that, but the OP may not.

#SelectExpand
1// C++, contrived 2struct Transform { 3 ALLEGRO_TRANSFORM transform; 4}; 5 6Transform t1; // t1 is defined at global scope, and so is t1.transform. 7Transform * t2 = NULL; // No Transform has been allocated; only a 4 or 8 byte integer (pointer) is allocated in global scope. 8 9void main(int argc, char ** argv) { 10 Transform t3; // Allocated on the stack. 11 Transform * t4 = new Transform(); // malloc-family in C, operator new() in C++ allocate on the heap; t4 is an integer (pointer) on the stack, but it points to a Transform object allocated on the heap; t4->transform is also on the heap. 12 13 t2 = &t3; // Now the global pointer points at a Transform object on the stack, and so t2->transform is also on the stack. 14 t2 = t4; // Now the global pointer points at a Transform object on the heap, and so t2->transform is also on the heap; 15 t2 = NULL; 16 17 // Every operator new() needs a corresponding operator delete() (at runtime as the program is running, not just in code) 18 delete t4; 19 t4 = NULL; 20}

I wrote this on my phone so hopefully I didn't miss any typos. If the OP or anyone doesn't understand this ask questions! That's what we're here for!

J43G3R

Problem Solved! Thankyou everyone who replied , and yes I was making the mistake of declaring a pointer without actually allocating memory for the ALLEGRO_TRANSFORM struct

bamccaig

Glad you and Erin got it solved. :D

Thread #618428. Printed from Allegro.cc