![]() |
![]() |
#1 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
![]()
Hi, cant get sprites to work in amidevcpp - have been trying for days
![]() I open the screen with: Code:
genscreen = OpenScreenTags(NULL, SA_DisplayID, LORES_KEY, SA_Depth, 4, // Give me a lot of border SA_Width, 320, SA_Height, 256, SA_Overscan, 0, // Hold the titlebar, please SA_Quiet, TRUE, // Give me sysfont 0 as default rastport font. SA_SysFont, 1, SA_Draggable,0, SA_Exclusive,1, SA_Colors,ColorSpec, SA_Type, CUSTOMSCREEN, TAG_DONE); My spritedata: Code:
UWORD sprite_data[]={ 0, 0, /* position control */ 0xffff, 0x0000, /* image data line 1, color 1 */ 0xffff, 0x0000, /* image data line 2, color 1 */ 0x0000, 0xffff, /* image data line 3, color 2 */ 0x0000, 0xffff, /* image data line 4, color 2 */ 0x0000, 0x0000, /* image data line 5, transparent */ 0x0000, 0xffff, /* image data line 6, color 2 */ 0x0000, 0xffff, /* image data line 7, color 2 */ 0xffff, 0xffff, /* image data line 8, color 3 */ 0xffff, 0xffff, /* image data line 9, color 3 */ 0, 0 /* reserved, must init to 0 0 */ }; Code:
struct SimpleSprite * sprite; int sprite_num = GetSprite(sprite, 1); if (sprite_num != -1) { // here still is ok, usually get sprite num =1 // create a emty pointer UWORD * spritedata; // allocate chipmemory spritedata=(UWORD) AllocMem(sizeof(sprite_data),MEMF_CHIP); // copy sprite data into chipmemory CopyMem(sprite_data,spritedata,sizeof(sprite_data)); // still all ok - get correct data in spritedata ChangeSprite(NULL, sprite, &spritedata); // no error // but no sprite!!! } sprite->x=0; sprite->y=0; sprite->height=9; but cant do that in amidevcpp - get compile error "dereferencing pointer to incomplete type" Any help is appreciated. Regards.... |
![]() |
![]() |
#2 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
i cannot help here, but you should copy the exact error message from the "Compiler Log" tab,
and the source code lines where it find the error you describe. |
![]() |
![]() |
#3 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
Its on the first line
Sprite->x = 0; Or if i comment that than on the next line |
![]() |
![]() |
#4 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
ah, ok, this is your code:
Code:
... sprite->x=0; sprite->y=0; sprite->height=9; ... "struct SimpleSprite { ... };" is missing. does it have the "members" x, y, height? there should be something like that: Code:
struct SimpleSprite { int x; int y; int height; }; Last edited by emufan; 26 September 2017 at 01:18. |
![]() |
![]() |
#5 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
struct SimpleSprite
{ UWORD *posctldata; UWORD height; UWORD x,y; /* current position */ UWORD num; }; In sprite.h which comes with amidevcpp. |
![]() |
![]() |
#6 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
hmm, you have #include <sprite.h> in you source file ?
![]() on stackoverflow someone suggest to allocate mem for that struct: Code:
struct SimpleSprite * sprite = malloc(sizeof(SimpleSprite)); |
![]() |
![]() |
#7 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
Tried it allready but the getsprite acctually changes the pointer. So alloc is the leak then. Anyhow already tried and no help
![]() |
![]() |
![]() |
#8 | |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
Quote:
![]() #1) where do you have the "sprite->x =0;" lines? i think they have to be in the same function and below the "struct SimpleSprite * sprite;" line. Code:
struct SimpleSprite * sprite; sprite->x=0; sprite->y=0; sprite->height=9; int sprite_num = GetSprite(sprite, 1); if (sprite_num != -1) { Last edited by emufan; 26 September 2017 at 01:56. |
|
![]() |
![]() |
#9 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
Well not really, it needs to be bellow if, in that place pointer is still empty.
But it makes no difference, cant access any members anywhere |
![]() |
![]() |
#10 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
|
![]() |
![]() |
#11 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
Same error... tricky isnt it
![]() ![]() |
![]() |
![]() |
#12 | |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
Quote:
![]() #1) another one from my lightwave plugin stuff. they do initialze the member before they do the struct, in this case typedef struct: Code:
int spln,dirn,thickness; double darken,brighten; typedef struct VIDIMAGE_TAG{ int spln; int dirn; int thickness; double darken; double brighten; } VIDIMAGE; .... // this is a function, LWInstance / LWError are known types LWInstance create(LWError *error) { VIDIMAGE *lwinst; lwinst = malloc(sizeof(struct VIDIMAGE_TAG)); if (!lwinst) { *error = "Error allocating memory!"; return NULL; } lwinst->thickness = 1; lwinst->spln = 4; lwinst->darken = 0.75; lwinst->brighten = 0.0; ... }; |
|
![]() |
![]() |
#13 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
Thats perfect for this example.
I use that all the time. But the pointer within simpleSprite i think is not allowing to access any element. No matter how are they allocated. |
![]() |
![]() |
#14 | |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
Quote:
I thought you have to use all of them, but what you do, is just set some values for a certain member. this is strange. maybe that pointer has to get initialized prior using the sprite struct? #1) i would just make a copy of sprite.h, and edit that struct, move the *posctldata to the last position of that struct. just to see what happens ![]() |
|
![]() |
![]() |
#15 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
yup, that works, tried it now - no problems.
but that structure needs to be like this - for system calls, cant just move pointer down... |
![]() |
![]() |
#16 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
Well, thanks a lot!!! you got me thinking in a different direction.
struct SimpleSprite1 { APTR posctldata; UWORD height; UWORD x,y; UWORD num; }; Recreating that struck like this works just fine, sprite show and all!!! Great help!!! |
![]() |
![]() |
#17 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
*wow* cool stuff - some h3x07ing did it
![]() #1) I cannot find the APTR example i was looking for. I had some issue with such type the other day, but in this case you replaced UWORD with the APTR type, so it must have been something different ![]() Last edited by emufan; 26 September 2017 at 02:51. |
![]() |
![]() |
#18 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
This is just a gift that keeps giving.
Now everything work in WinUAE, but not on real machine - no sprite is visible... Code:
// add sprite sprite_num = GetSprite(&sprite, 2); if (sprite_num != -1) { sprite.x = 0; sprite.y = 0; sprite.height = 32; // color pallete SetRGB4(&genscreen->ViewPort, 21,0,0,0); // allocate chipmemory spritedata=(UWORD) AllocMem(sizeof(sprite_data),MEMF_CHIP); if (spritedata > 0) { // copy sprite data into chipmemory CopyMem(&sprite_data,spritedata,sizeof(sprite_data)); ChangeSprite(&genscreen->ViewPort, &sprite, spritedata); MoveSprite(&genscreen->ViewPort, &sprite, 30,10); } else { DisplayAlert(RECOVERY_ALERT,"\x00\xF0\x14" "Could not allocate memory for sprite!",64); } } else { DisplayAlert(RECOVERY_ALERT,"\x00\xF0\x14" "Could not allocate sprite!",64); } ![]() |
![]() |
![]() |
#19 |
Registered User
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
|
hmm, do you run it from shell/cli? maybe add some printf's in those conditions like:
Code:
if (spritedata > 0) { printf("spritedata > 0\n"); printf("&sprite == %d\n", &sprite); ... |
![]() |
![]() |
#20 |
Registered User
Join Date: Sep 2017
Location: Novi Sad
Posts: 23
|
Did bunch of printf debuging this morning.
All is in order! Memory, pointers, sprite num etc. but no sprite on screen ![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Amidevcpp c++ link errors | tolkien | Coders. C/C++ | 8 | 08 November 2019 01:18 |
AmiDevCpp $(GLOBALDEPS) | mritter0 | Coders. C/C++ | 1 | 29 June 2015 01:30 |
AmiDevCpp | AF2013 | Coders. C/C++ | 0 | 14 March 2014 00:23 |
Problem compiling with AmiDevCpp | Franchute13 | Coders. C/C++ | 2 | 26 September 2013 15:01 |
AmiDevCpp and Floats | AmigaEd | Coders. General | 0 | 18 January 2006 03:16 |
|
|