Crash with Array::Insert and static event handler

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
Player701
 
 
Posts: 1636
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Crash with Array::Insert and static event handler

Post by Player701 »

The following ZScript will cause GZDoom to crash upon loading a map, provided that the event handler has been registered in MAPINFO:

Code: Select all

class TestHandler : StaticEventHandler
{
    Array<MyClass> ar;
    
    override void OnRegister()
    {
        ar.Insert(1, new('MyClass'));
    }
}

class MyClass
{    
}
I have attached a WAD to reproduce the crash. Tested in GZDoom 4.4.2 and g4.5pre-230-g89cc69710
Attachments
insert_crash.wad
(301 Bytes) Downloaded 19 times
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Crash with Array::Insert and static event handler

Post by Major Cooke »

Does it crash when you do the 'new' first as a variable and then insert it?

Also, just a note, Graf has said OnRegister should be avoided for everything except setting the order.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Crash with Array::Insert and static event handler

Post by Graf Zahl »

Can't check right now, but inserting at index 1 in an empty array surely is undefined behavior at the very best and should probably abort.
User avatar
Player701
 
 
Posts: 1636
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Crash with Array::Insert and static event handler

Post by Player701 »

IMO, it should initialize the elements at all previous indices (0 in this case) with default values (null, 0, false etc. depending on the type). However, an abort would at least be better than a crash. Note that I did this with an array of numeric values previously, and everything worked just fine - of course I never touched the values at indices where I didn't insert anything. It's only logical to expect an object array to behave in the same way.
Major Cooke wrote:Does it crash when you do the 'new' first as a variable and then insert it?

Also, just a note, Graf has said OnRegister should be avoided for everything except setting the order.
It does, because the problem is with the insertion, and not with the generated code. The crash happens during a GC pass.

Regarding OnRegister et al., my experience is that everything will work normally as long as you know what APIs are safe to call at each entry point in your script code. Creating objects and populating an array doesn't involve any external APIs at all, so I don't see any reason why it should suddenly break.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Crash with Array::Insert and static event handler

Post by Graf Zahl »

fixed
Post Reply

Return to “Closed Bugs [GZDoom]”