Page 1 of 2

PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 4:41 am
by said
Hi All,

Finally i was able to reproduce what looks to me like a bug (not necessarily in PB!) on a readable scale ... Here is the code:

Code: Select all

EnableExplicit

Structure TC
    S1.s
    S2.s
    S3.s
    Array M.f(0)
    F1.f
    F2.f
    Map  mp1.i()
    List lst.s()
EndStructure

Structure TH
    List   lstTCs.TC()
    Array  AM.i(0)
    Array  RQ.i(0)
EndStructure
Structure TS
    H1.TH
    H2.TH
    H3.TH
EndStructure

Global S.TS , Event, Counter, Mtx = CreateMutex()

Procedure TC_Init(*C.TC)
    ClearStructure(*C, TC)
    InitializeStructure(*C, TC)
    Dim *C\M( 30 )
    *C\F1 = 1.0
EndProcedure
Procedure TC_Copy(*Org.TC, *Dst.TC)
    CopyStructure(*Org, *Dst, TC)
EndProcedure

Procedure TH_Init(*H.TH)
    ClearStructure(*H, TH)
    InitializeStructure(*H, TH)
EndProcedure
Procedure TH_Copy(*Org.TH, *Dst.TH)
    CopyStructure(*Org, *Dst, TH)
EndProcedure
Procedure TH_Add_C(*H.TH, *C.TC, Position = -1)
    Protected n
    
    n = ListSize(*H\lstTCs())
    If Position >= 0 And Position < n
        SelectElement(*H\lstTCs(), Position)
        InsertElement(*H\lstTCs())
        TC_Copy( *C, @*H\lstTCs())
    Else
        LastElement(*H\lstTCs())
        AddElement(*H\lstTCs())
        TC_Copy( *C, @*H\lstTCs())
    EndIf
    
EndProcedure

Procedure Fill_H(*S.TS)
    Protected C.TC, i, n = 100000
    
    TH_Init(*S\H1)
    For i=1 To n
        TC_Init(@C)
        C\S1 = "A" + Str(i)
        C\mp1("123") = 123
        AddElement(C\lst()) : C\lst() = "123"
        
        TH_Add_C(*S\H1, @C)
        LockMutex(Mtx)
        Counter + 1
        UnlockMutex(Mtx)
    Next
    MessageRequester("Done","You can close now")
    
EndProcedure


  If OpenWindow(0, 0, 0, 230, 90, "crash on win 8.1 ...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

   ButtonGadget(1, 10, 10, 200, 25, "Click me")
   TextGadget(2, 10, 50, 200, 25, "")
   AddWindowTimer(0, 3, 100)
   
   Repeat
     Event = WaitWindowEvent()
     
     Select Event
     
       Case #PB_Event_Gadget
         If EventGadget() = 1
           DisableGadget(1, 1)
           CreateThread(@Fill_H(), @S)
         EndIf
     Case #PB_Event_Timer 
        If EventTimer() = 3
          LockMutex(Mtx)
          SetGadgetText(2, Str(Counter))
          UnlockMutex(Mtx)
        EndIf 
     
     EndSelect
   Until Event = #PB_Event_CloseWindow
 EndIf



Here is what is going on:
1. I compile the above with PB 5.22 x86 on Win 8.1 the exe crashes with 0xc0000005 'magical' error
2. I set the compatibility mode of that EXE to Windows 8 or earlier, it runs fine :shock:
3. I take that same exe to my win7 pc it just runs fine
4. I run from the IDE PB5.22 x86 it crashes
5. I set the compatibility mode of PB IDE to Windows 8 or earlier, it runs fine
6. I run/compile with PB 5.22 x64 no issue everything is fine! No need to change compatibility mode or anything else

So,
Is it my code ? Is it PB ? Is it Win 8.1 ? Is it my pc ? is it the color of my shirt

Any help is appreciated ( the above needs be compiled with Thread-safe)

Thanks

Said

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 5:13 am
by Kuron
said wrote:Any help is appreciated ( the above needs be compiled with Thread-safe)
This is possibly your problem. If you are using threads and you are using a 64-bit version of Windows, you really need to be using a 64-bit EXE.

The 32-bit emulation used (WoW64) on 64-bit versions of Windows, has known issues with threads, and MS will not fix it (and likely can't). These issues have existed since XP64 and they are still in the latest version of Windows 8.1 64. 32-bit emulation was designed to allow legacy software to still run, it is NOT intended for writing and supporting new 32-bit software.

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 5:43 am
by TI-994A
Kuron wrote:...If you are using threads and you are using a 64-bit version of Windows, you really need to be using a 64-bit EXE.

The 32-bit emulation used (WoW64) on 64-bit versions of Windows, has known issues with threads, and MS will not fix it (and likely can't). These issues have existed since XP64 and they are still in the latest version of Windows 8.1 64. 32-bit emulation was designed to allow legacy software to still run, it is NOT intended for writing and supporting new 32-bit software.
Hi Kuron. If that's the case, then it should also fail on Win7 x64; but it doesn't.

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 6:05 am
by said
Kuron wrote:
said wrote:Any help is appreciated ( the above needs be compiled with Thread-safe)
This is possibly your problem. If you are using threads and you are using a 64-bit version of Windows, you really need to be using a 64-bit EXE.

The 32-bit emulation used (WoW64) on 64-bit versions of Windows, has known issues with threads, and MS will not fix it (and likely can't). These issues have existed since XP64 and they are still in the latest version of Windows 8.1 64. 32-bit emulation was designed to allow legacy software to still run, it is NOT intended for writing and supporting new 32-bit software.
Thanks for your response, good to know ... but i doubt this is the only reason, isn't PB IDE x86 a 32bits multi-threaded application ? it is running fine on the same pc!
TI-994A wrote: ... If that's the case, then it should also fail on Win7 x64; but it doesn't.
Indeed it is running fine on win7 x64 (as mentioned above) Thanks TI-994A

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 6:09 am
by Thunder93
Not that I'm calling anyone a liar. It would be nice though If links to official documentations detailing known problems with thread usage on x64 Windows when working with 32bit applications... I haven't had the need for threads, or at least not aggressively, for lot of small projects that I've done thus far. However, beginning to take more advantage of thread support for some things I'm doing recently.

Poor practises to implement feature that will only work in some cases and not make note anywhere about this. It would be a pretty big deal if problems exists from use of threads in 32-bit applications running under x64 Windows. Not Frederic style, ... how I've observed it anyways.

TI-994A beats me to the punch... That is what I get for being a slow poster. :x

Like TI-994A stated. If that's the case then it should also fail with using x86 PB on Win7 x64. Tried multiple times to reproduce on Win7 x64, and not a single problem, everything is working perfectly.

Therefore there must be a change in 8.1 that Frederic needs to adapt to, or is a introduced bug with 8.1 update.

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 6:40 am
by Thunder93
I browsed the web, found some problems with multi-threaded applications under 8.1 x64. I think it's safe to assume that Microsoft introduced a bad update and hopefully soon patch will follow.

For the meantime, stop running your 32bit threaded applications under Win8.1 x64. :lol:

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 7:16 am
by Kuron
said wrote:Thanks for your response, good to know ... but i doubt this is the only reason, isn't PB IDE x86 a 32bits multi-threaded application ? it is running fine on the same pc!
The thread issues depend on how the threads are being used. Yours sounds more like increased protections on Windows 8, since it is working on Windows 7 64 (I missed that part first read). And I only ever said this was possibly the reason, I never said it was the reason. But it is one of the reasons I would no longer write 32-bit Windows software if I was still supporting Windows.

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 7:46 am
by PB
> Therefore there must be a change in 8.1 that Frederic needs to adapt to

Probably. PureBasic v5.22 LTS was released March 2014, and Win 8.1 Update
was released a month later in April 2014. Something probably got changed.

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 8:00 am
by Kuron
Not that I'm calling anyone a liar. It would be nice though If links to official documentations detailing known problems with thread usage on x64 Windows when working with 32bit applications.
For what I am referring to and has links to other articles and MS sources.

http://zachsaw.blogspot.co.uk/2010/11/w ... eturn.html

This details issues that have been there since XP64.

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 11:17 am
by Thunder93
Nice one. Thanks. :)

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 12:45 pm
by said
Thunder93 wrote:I browsed the web, found some problems with multi-threaded applications under 8.1 x64. I think it's safe to assume that Microsoft introduced a bad update and hopefully soon patch will follow.

For the meantime, stop running your 32bit threaded applications under Win8.1 x64. :lol:
Yes there have been many reports on the web about 32bits apps crashing on 8.1 x64 while running fine on previous windows, but these are mostly games which require driver updates :cry:

i can personally stop running such apps on my pc (or set the compatibility mode back to Win 8) but what about my clients :?: :twisted:

As for that blog post, it is true the mentioned issue still exists to date but the original post back in 2010 was mainly about XP x64 and i doubt the PB team is not ware of that :!:

Honestly i believe the issue is somewhere else, let's wait for the PB team reply on this ...

Meanwhile, has anyone else able to reproduce this crash ?

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 12:59 pm
by Thunder93
Yep I saw those too. But I was referring to applications - http://en.wikipedia.org/wiki/Application_software, and not games.

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 4:53 pm
by Teddy Rogers
I have been using threads for some 32/64bit PB code and I have had absolutely no problems with running them under Windows 8.x...

Without purifier running...
[23:48:15] Waiting for executable to start...
[23:48:15] Executable type: Windows - x86 (32bit, Unicode)
[23:48:15] Executable started.
[23:48:18] [ERROR] Line: 54
[23:48:18] [ERROR] Invalid memory access. (write error at address 50)
[23:48:18] The Program execution has finished.

Code: Select all

        AddElement(*H\lstTCs())
With purifier running...
[23:58:12] Waiting for executable to start...
[23:58:12] Executable type: Windows - x86 (32bit, Unicode, Purifier)
[23:58:12] Executable started.
[23:58:15] [ERROR] Line: 66
[23:58:15] [ERROR] Invalid memory access. (write error at address 229376)
[23:58:15] The Program execution has finished.

Code: Select all

        C\S1 = "A" + Str(i)
Ted.

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Fri May 02, 2014 5:10 pm
by Thunder93
I wonder if boundary has been messed up with Win8.1?

Does it happen near the end of the counter? or the moment you click the button to start or half way?

If it's nearly to the end, what about stopping just before 100000. Then try with half that, and half of that even. :P

Re: PB x86 on Win 8.1 - driving me crazy

Posted: Sat May 03, 2014 12:12 am
by said
Thunder93 wrote:I wonder if boundary has been messed up with Win8.1?

Does it happen near the end of the counter? or the moment you click the button to start or half way?

If it's nearly to the end, what about stopping just before 100000. Then try with half that, and half of that even. :P
It seems to happen randomly sometimes at 16000 or over 100000 .... nothing consistent!


One thing for sure is the below code where the map and list field are commented, it no longer crashes!

Code: Select all

EnableExplicit

Structure TC
    S1.s
    S2.s
    S3.s
    Array M.f(0)
    F1.f
    F2.f
    ;Map  mp1.i()                       ; <<<<<<< when commented - no crash
    ;List lst.s()                       ; <<<<<<< when commented - no crash
EndStructure

Structure TH
    List   lstTCs.TC()
    Array  AM.i(0)
    Array  RQ.i(0)
EndStructure
Structure TS
    H1.TH
    H2.TH
    H3.TH
EndStructure

Global S.TS , Event, Counter, Mtx = CreateMutex()

Procedure TC_Init(*C.TC)
    ClearStructure(*C, TC)
    InitializeStructure(*C, TC)
    Dim *C\M( 30 )
    *C\F1 = 1.0
EndProcedure
Procedure TC_Copy(*Org.TC, *Dst.TC)
    CopyStructure(*Org, *Dst, TC)
EndProcedure

Procedure TH_Init(*H.TH)
    ClearStructure(*H, TH)
    InitializeStructure(*H, TH)
EndProcedure
Procedure TH_Copy(*Org.TH, *Dst.TH)
    CopyStructure(*Org, *Dst, TH)
EndProcedure
Procedure TH_Add_C(*H.TH, *C.TC, Position = -1)
    Protected n
    
    n = ListSize(*H\lstTCs())
    If Position >= 0 And Position < n
        SelectElement(*H\lstTCs(), Position)
        InsertElement(*H\lstTCs())
        TC_Copy( *C, @*H\lstTCs())
    Else
        LastElement(*H\lstTCs())
        AddElement(*H\lstTCs())
        TC_Copy( *C, @*H\lstTCs())
    EndIf
    
EndProcedure

Procedure Fill_H(*S.TS)
    Protected C.TC, i, n = 100000
    
    TH_Init(*S\H1)
    ;For i=1 To n
    Repeat
        TC_Init(@C)
        C\S1 = "A" + Str(i)
        ;C\mp1("123") = 123
        ;AddElement(C\lst()) : C\lst() = "123"
        
        TH_Add_C(*S\H1, @C)
        LockMutex(Mtx)
        Counter + 1
        UnlockMutex(Mtx)
    ForEver
    ;Next
    
    MessageRequester("Done","You can close now")
    
EndProcedure


  If OpenWindow(0, 0, 0, 230, 90, "crash on win 8.1 ...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

   ButtonGadget(1, 10, 10, 200, 25, "Click me")
   TextGadget(2, 10, 50, 200, 25, "")
   AddWindowTimer(0, 3, 100)
   
   Repeat
     Event = WaitWindowEvent()
     
     Select Event
     
       Case #PB_Event_Gadget
         If EventGadget() = 1
           DisableGadget(1, 1)
           CreateThread(@Fill_H(), @S)
         EndIf
     Case #PB_Event_Timer 
        If EventTimer() = 3
          LockMutex(Mtx)
          SetGadgetText(2, Str(Counter))
          UnlockMutex(Mtx)
        EndIf 
     
     EndSelect
   Until Event = #PB_Event_CloseWindow
 EndIf

Even more confusing! Looks more lie a PB bug now ?!