SetGadgetState seems to cause an invalid memory access error

Just starting out? Need help? Post your questions and find answers here.
Martin Verlaan
Enthusiast
Enthusiast
Posts: 124
Joined: Sun Apr 01, 2018 11:26 am

SetGadgetState seems to cause an invalid memory access error

Post by Martin Verlaan »

I made an audio player in PB and used Bass library for this. If I run the player, it crashes after several hours of non stop playing with an invalid memory access error. The error happens at the WaitWindowEvent() command (in repeat loop).

However, after many tests I think the problem is caused by a SetGadgetState command (called in a timer event).

Code: Select all

SetGadgetState(#Trackbar, ElapsedSeconds)   
The Setgadget command updates the trackbargadget to show the playing position of a song. Without this command the program did not crashed.

The question is: how can I prevent this memory error and why does it happen? I can't show the full code because it's long and a commercial project, but ofcourse i can post parts of it if needed.

Thanks,

Martin
b.t.w. I use Linux so maybe this error only occurs in Linux, I still must do a test in Windows.
Last edited by Martin Verlaan on Fri Sep 07, 2018 9:18 pm, edited 2 times in total.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Setgadget seems to cause an invalid memory access error

Post by Marc56us »

Did you test the value ?

(in help)

TrackBarGadget()

Minimum, Maximum The range of values used by the gadget. These values should be between 0 and 10,000 to avoid limitations on some operating systems.


PS. IMAs often happen when several program parts are trying to access the same gadget. Do you use threads ?

:wink:
Martin Verlaan
Enthusiast
Enthusiast
Posts: 124
Joined: Sun Apr 01, 2018 11:26 am

Re: Setgadget seems to cause an invalid memory access error

Post by Martin Verlaan »

Yes, values of trackbar are between valid range and I do not use threads (only a timer). However, a BASS sync is set with each song, which can maybe also be tricky. Still debugging... Thanks anyway!
Martin Verlaan
Enthusiast
Enthusiast
Posts: 124
Joined: Sun Apr 01, 2018 11:26 am

Re: Setgadget seems to cause an invalid memory access error

Post by Martin Verlaan »

Does the trackbargadget allow float values or only integer?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: SetGadgetState seems to cause an invalid memory access e

Post by Dude »

Martin Verlaan wrote:The error happens at the WaitWindowEvent() command
Invalid Memory Access errors don't usually occur on the reported line, so it won't be because of WaitWindowEvent().
Martin Verlaan wrote:Without [SetGadgetState] the program did not crashed.
This proves what I said above. You're obviously using SetGadgetState with an invalid value. Are you actually using failsafe code like "If value>0 And value<10000" before using SetGadgetState, or just using it and assuming the value will always be correct?

Anyway, try to reproduce the bug with a small standalone snippet of runnable code, and you'll usually spot your bug when doing so. It's called Rubber Duck Debugging ;)
Martin Verlaan
Enthusiast
Enthusiast
Posts: 124
Joined: Sun Apr 01, 2018 11:26 am

Re: SetGadgetState seems to cause an invalid memory access e

Post by Martin Verlaan »

I finally solved the problem. The cause of the problem was a timer event that updates some gadgets. This also happened while running BASS_Mixer_ChannelSetSync callbacks. This caused memory errors (even when all variables have correct values). I have turned off the timer in these callbacks and the program now seems to be running stably :mrgreen:
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: SetGadgetState seems to cause an invalid memory access e

Post by infratec »

You enabled 'Thread save' :?:
Martin Verlaan
Enthusiast
Enthusiast
Posts: 124
Joined: Sun Apr 01, 2018 11:26 am

Re: SetGadgetState seems to cause an invalid memory access e

Post by Martin Verlaan »

ehm..no i didn't. Would that prevent those memory errors? I didn't know that this option also can be used for external libraries.
Post Reply