B4R Question ObjectCopy - Esp32

janderkan

Well-Known Member
Licensed User
Longtime User
I am using this code in Esp8266 to copy from Eeprom to a string :

B4X:
    Dim DynMqttServer As String = BC.StringFromBytes(EE.ReadBytes(ptrMqttserver+Offset,32))
    BC.ObjectCopy(DynMqttServer, MqttServer, DynMqttServer.Length + 1)

but on my Esp32 it restarts continously :

B4X:
AppStart
Guru Meditation Error: Core  1 panic'ed (LoadStoreError). Exception was unhandled.
Core 1 register dump:
PC      : 0x4000c3f5  PS      : 0x00060330  A0      : 0x800d2960  A1      : 0x3ffb1ee0
A2      : 0x3f401148  A3      : 0x3ffb8208  A4      : 0x00000001  A5      : 0x0000ff00
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3f401148
A10     : 0x00000000  A11     : 0x3ffb8859  A12     : 0x3ffb860c  A13     : 0x00000000
A14     : 0x00000000  A15     : 0xff000000  SAR     : 0x0000001c  EXCCAUSE: 0x00000003
EXCVADDR: 0x3f401148  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff
Backtrace: 0x4000c3f5:0x3ffb1ee0 0x400d295d:0x3ffb1f00 0x400d385e:0x3ffb1f20 0x400d3177:0x3ffb1f70 0x400d3f0a:0x3ffb1f90 0x400d6f57:0x3ffb1fb0 0x40088f1d:0x3ffb1fd0
Rebooting...
 

janderkan

Well-Known Member
Licensed User
Longtime User
I am using this code in Esp8266 to copy from Eeprom to a string :

B4X:
    Dim DynMqttServer As String = BC.StringFromBytes(EE.ReadBytes(ptrMqttserver+Offset,32))
    BC.ObjectCopy(DynMqttServer, MqttServer, DynMqttServer.Length + 1)


SOLVED !
It helps to check if the length of the string is not zero. :)
 
Upvote 0

janderkan

Well-Known Member
Licensed User
Longtime User
Hi again

The error still persists.

This code will compile, but the Esp32 restarts continuously, see error in first post.

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    
    Public BC As ByteConverter
    
    Public MyString As String = "00000"
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    
    Dim DynString As String = "hi"
    If DynString.Length>0 Then BC.ObjectCopy(DynString, MyString, MyString.Length)

    Log(MyString)
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Constant strings can be optimized and stored in read-only memory.

Change your code to:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Public BC As ByteConverter
   Public MyString(10) As Byte
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   Dim DynString() As Byte = "hi"
   If DynString.Length>0 Then BC.ObjectCopy(DynString, MyString, MyString.Length)
   Log(MyString)
End Sub

Though I would have used GlobalStore instead.
https://www.b4x.com/android/forum/threads/73863/#content
 
Upvote 0
Top