Print Topic - Archive
XBLite Forum / XBLite Compiler / INC bug ?
Posted by: 26 (Guest), September 21, 2008, 10:02am
I had an exception raised when excuting this code
Quoted Text
INC mControl.nMenus
and none when using this one :
Quoted Text
mControl.nMenus = mControl.nMenus + 1
That was very weird so it took a look to the assembly code :
Quoted Text
; [3449] INC mControl.nMenus
mov eax,d[%mControl.sab_edit] ;;; i663a
mov esi,d[eax+4] ;;; i73
inc d[eax+4] ;;; i78
jnc > A.372 ;;; i79
int 3 ;;; i80
A.372:
So this is the problem, the code executes INT3 if carry is set but INC does not modify carry flag so you can have unexpected exceptions when using INC (totaly randomly so it is difficult to find why).
Posted by: XBLiteAdmin, September 26, 2008, 11:26am; Reply: 1
Hi,
I'm unable to explain this situation without more code to look at.
Could you post your struct for mControl.
thanks,
D.
Posted by: 26 (Guest), September 26, 2008, 3:35pm; Reply: 2
composites are defined as :
|
Code
PACKED RGBA_F
SINGLE .r
SINGLE .g
SINGLE .b
SINGLE .a
END TYPE
TYPE MENU_COLOR_SET
RGBA_F .text
RGBA_F .base
END TYPE
TYPE MENU_CONTROLER
ULONG .font
ULONG .nMenus
ULONG .focused
MENU_COLOR_SET .focus
MENU_COLOR_SET .active
MENU_COLOR_SET .inactive
END TYPE |
|
and the function is :
|
Code
FUNCTION MENU_Create (pX,pY,width,title$)
SHARED MENU_CONTROLER mControl
SHARED MENU_HANDLER menu[]
cMenu=mControl.nMenus
IF cMenu>$$MAX_MENUS THEN RETURN -1
'mControl.nMenus = mControl.nMenus + 1
INC mControl.nMenus
menu[cMenu].flags=0
menu[cMenu].nItems=0
menu[cMenu].pos.x=pX
menu[cMenu].pos.y=pY
menu[cMenu].width=width
menu[cMenu].name =title$
RETURN cMenu
END FUNCTION
|
|
Alone this code causes exception.If i clear carry flag before using INC/DEC (composite.member), the exception does not occur.If the carry flag is set before any INC/DEC (composite.member), exception raises each time.
|
Code
ASM clc
INC mControl.nMenus
|
|
will not cause exception
|
Code
ASM stc
INC mControl.nMenus
|
|
will cause exception each time
|
Code
PRINT "someting"
INC mControl.nMenus
|
|
will avoid exception (i suppose PRINT clears carry flag)
This problems seems to occur only with composites ULONG members.
I attached a bit of code that reproduces problem.In this program, i suppose the 'IF THEN' code set the carry flag so the problem occurs.This is dependency walker output :
Quoted Text
00:00:00.203: First chance exception 0x80000003 (Breakpoint) occurred in "TESTINC.EXE" at address 0x0040105A by thread 1.
Posted by: eto.ethome.sk, November 26, 2008, 11:43pm; Reply: 3
I have experienced exactly the same situation today. Invoking INC caused second chance exception, which took down whole program. I was using PACKED type with ULONG memebers, are you interested in my source code for further anlysis?
Print page generated: February 5, 2012, 2:40pm