|
using transform |
J43G3R
Member #20,281
June 2021
|
can someone point me to correct method of initialising transformations. I created a pointer to ALLEGRO_TRANSFORM and invoked al_identity_tranform on it. This is the error |
DanielH
Member #934
January 2001
|
You're passing a pointer? Does it actually point to an ALLEGRO_TRANSFORM? |
Erin Maus
Member #7,537
July 2006
|
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
Member #7,536
July 2006
|
A class or struct field is not implicitly on the heap at all. Where it is allocated depends on how you define an instance of it. I know (hope) Erin knows that, but the OP may not. 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! -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
J43G3R
Member #20,281
June 2021
|
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
Member #7,536
July 2006
|
Glad you and Erin got it solved. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
|