OMG:
int32_t contextWidth;
REALGetPropValueInt32((REALobject)rbContext, "Width", &contextWidth);
NSLog(@" StateChanged: contextWidth %d", contextWidth);
int32_t contextHeight;
REALGetPropValueInt32((REALobject)rbContext, "Height", &contextHeight);
NSLog(@" StateChanged: contextHeight %d", contextHeight);
CGSize rbContextSize = CGSizeMake(contextWidth, contextHeight);
NSLog(@" StateChanged: drawing, rbContextSize:%@", NSStringFromSize(rbContextSize));
The first call to get the width of the context succeeds, and so does the second call to get the height. The OMG is when you use these values. So the experiment is:
default 10:03:33.259906-0400 Xojo StateChanged: contextWidth 320
default 10:03:33.260085-0400 Xojo StateChanged: contextHeight 368
default 10:03:33.260123-0400 Xojo StateChanged: drawing, rbContextSize:{0, 368}
If you call the contextHeight first followed by the contextWidth, the output of the size becomes {320, 0}.
<https://xojo.com/issue/65300 >
Try REALGetPropValueInteger, instead of Int32, since the Width of Graphics is Integer and not Int32.
Cannot promise it will change anything, it was just something I see in quick look.
I did:
int32_t contextWidth;
REALGetPropValueInt32((REALobject)rbContext, "Width", &contextWidth);
NSLog(@" StateChanged: contextWidth %d", contextWidth);
cw = contextWidth;
int32_t contextHeight;
REALGetPropValueInt32((REALobject)rbContext, "Height", &contextHeight);
NSLog(@" StateChanged: contextHeight %d", contextHeight);
ch = contextHeight;
CGSize rbContextSize = CGSizeMake(contextWidth, contextHeight);
NSLog(@" StateChanged: drawing, rbContextSize:%@", NSStringFromSize(rbContextSize));
CGSize rbSize = CGSizeMake(cw, ch);
NSLog(@" StateChanged: drawing, rbSize:%@", NSStringFromSize(rbSize));
The assignment to another variable (cw and ch) fixed it.
You should really initialize variables to 0 or -1 to later check if they got a value.
Or check the results of REALGetPropValueInt32 calls.
Björn_Eiríksson:
Try REALGetPropValueInteger, instead of Int32, since the Width of Graphics is Integer and not Int32.
Cannot promise it will change anything, it was just something I see in quick look.
Thanks,
that’s the explanation:
RBInteger contextWidth;
RBInteger contextHeight;
REALGetPropValueInteger((REALobject)rbContext, "Width", &contextWidth);
NSLog(@" StateChanged: contextWidth %lld", contextWidth);
REALGetPropValueInteger((REALobject)rbContext, "Height", &contextHeight);
NSLog(@" StateChanged: contextHeight %lld", contextHeight);
CGSize rbContextSize = CGSizeMake(contextWidth, contextHeight);
NSLog(@" StateChanged: drawing, rbContextSize:%@", NSStringFromSize(rbContextSize));
default 08:02:58.690392-0400 Xojo StateChanged: contextWidth 320
default 08:02:58.690416-0400 Xojo StateChanged: contextHeight 368
default 08:02:58.690440-0400 Xojo StateChanged: drawing, rbContextSize:{320, 368}
Could it be that you ask for Int32, but Xojo delivers Int64 and overwrites the other variable on the stack next to it?
Yes, that apparently is the issue